#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "portable.h"
#include "libdali.h"
Functions | |
int | dlp_sockstartup (void) |
Start up socket subsystem (only does something for Win32). | |
int | dlp_sockconnect (int socket, struct sockaddr *inetaddr, int addrlen) |
Connect a network socket. | |
int | dlp_sockclose (int socket) |
Close a network socket. | |
int | dlp_sockblock (int socket) |
Set a network socket to blocking mode. | |
int | dlp_socknoblock (int socket) |
Set a network socket to non-blocking mode. | |
int | dlp_noblockcheck (void) |
Check if socket action would have blocked. | |
int | dlp_setsocktimeo (int socket, int timeout) |
Set socket I/O timeout. | |
int | dlp_setioalarm (int timeout) |
Set a network I/O real time alarm. | |
int | dlp_getaddrinfo (char *nodename, char *nodeport, struct sockaddr *addr, size_t *addrlen) |
Resolve IP address and prepare paramters for connect(). | |
int | dlp_openfile (const char *filename, char perm) |
Open a file stream. | |
const char * | dlp_strerror (void) |
Return a description of the last system error. | |
int64_t | dlp_time (void) |
Determine the current system time. | |
void | dlp_usleep (unsigned long int useconds) |
Sleep for a specified number of microseconds. | |
int | dlp_genclientid (char *progname, char *clientid, size_t maxsize) |
Generate a DataLink client ID from system & process information. |
Platform portability routines.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License (GNU-LGPL) for more details. The GNU-LGPL and further information can be found here: http://www.gnu.org/
modified: 2008.193
int dlp_genclientid | ( | char * | progname, | |
char * | clientid, | |||
size_t | maxsize | |||
) |
Generate a DataLink client ID from system & process information.
Generate a client ID composed of the program name, the current user name and the current process ID as a string where the fields are separated by colons:
"progname:username:pid:arch"
The client ID string is written into a supplied string which must already be allocated.
progname | Name of program, usually argv[0] | |
clientid | Generated client ID string will be written to this string | |
maxsize | Maximum bytes to write to clientid string. |
int dlp_getaddrinfo | ( | char * | nodename, | |
char * | nodeport, | |||
struct sockaddr * | addr, | |||
size_t * | addrlen | |||
) |
Resolve IP address and prepare paramters for connect().
Resolve IP addresses and provide parameters needed for connect(). On Win32 this will use gethostbyname() for portability (only newer Windows platforms support getaddrinfo). On Linux (glibc2) and Solaris the reentrant gethostbyname_r() is used.
The real solution to name resolution is to use POSIX 1003.1g getaddrinfo() because it is standardized, thread-safe and protocol independent (i.e. IPv4, IPv6, etc.). Unfortunately it is not supported on many older platforms.
nodename | Hostname to resolve | |
nodeport | Port number to connect to | |
addr | Returned struct sockaddr for connect() | |
addrlen | Returned length of addr |
int dlp_noblockcheck | ( | void | ) |
Check if socket action would have blocked.
Check the global error status and test if the error indicates that the recent socket action failed because it would have blocked.
int dlp_openfile | ( | const char * | filename, | |
char | perm | |||
) |
Open a file stream.
Open a specified file and return the file descriptor. The perm character is interpreted the following way:
perm: 'r', open file with read-only permissions 'w', open file with read-write permissions, creating if necessary.
filename | File to open | |
perm | Permission flag |
int dlp_setioalarm | ( | int | timeout | ) |
Set a network I/O real time alarm.
Set a network I/O alarm timer, the timeout is specified in seconds. The timer is disabled by setting the timeout to zero. On most platforms this will cause a SIGALARM signal to be sent to the calling process after timeout seconds have elapsed. This function does nothing under Win32.
timeout | Alarm timeout in seconds |
int dlp_setsocktimeo | ( | int | socket, | |
int | timeout | |||
) |
Set socket I/O timeout.
Set socket I/O timeout if such an option exists. On Win32 and other platforms where SO_RCVTIMEO and SO_SNDTIMEO are defined this sets the SO_RCVTIMEO and SO_SNDTIMEO socket options using setsockopt() to the timeout value (specified in seconds).
Solaris does not implelement socket-level timeout options.
socket | Network socket descriptor | |
timeout | Alarm timeout in seconds |
int dlp_sockblock | ( | int | socket | ) |
Set a network socket to blocking mode.
Set a network socket to blocking mode.
socket | Network socket descriptor |
int dlp_sockclose | ( | int | socket | ) |
Close a network socket.
Close a network socket.
socket | Network socket descriptor |
int dlp_sockconnect | ( | int | socket, | |
struct sockaddr * | inetaddr, | |||
int | addrlen | |||
) |
Connect a network socket.
Connect a network socket and perform error checking.
socket | Network socket descriptor | |
inetaddr | The struct sockaddr, passed to connect() | |
addrlen | Length of inetaddr, passed to connect() |
int dlp_socknoblock | ( | int | socket | ) |
Set a network socket to non-blocking mode.
Set a network socket to non-blocking mode.
socket | Network socket descriptor |
int dlp_sockstartup | ( | void | ) |
Start up socket subsystem (only does something for Win32).
Startup the network socket layer. At the moment this is only meaningful for the WIN32 platform and requests Windows sockets version 2.2.
const char* dlp_strerror | ( | void | ) |
Return a description of the last system error.
int64_t dlp_time | ( | void | ) |
Determine the current system time.
Determine the current time from the system as a dltime_t value. On the WIN32 platform this function has millisecond resulution, on Unix platforms this function has microsecond resolution.
void dlp_usleep | ( | unsigned long int | useconds | ) |
Sleep for a specified number of microseconds.
Sleep for a given number of microseconds. Under Win32 use SleepEx() and for all others use the POSIX.4 nanosleep(), which can be interrupted by signals.
useconds | Microseconds to sleep. |