libdali  1.6
 All Classes Files Functions Variables Typedefs Macros Pages
Macros | Typedefs | Functions
portable.h File Reference

Go to the source code of this file.

Typedefs

typedef signed char int8_t
 
typedef unsigned char uint8_t
 
typedef signed short int int16_t
 
typedef unsigned short int uint16_t
 
typedef signed int int32_t
 
typedef unsigned int uint32_t
 
typedef signed long long int64_t
 
typedef unsigned long long uint64_t
 

Functions

int dlp_sockstartup (void)
 Start up socket subsystem (only does something for Win32) More...
 
int dlp_sockconnect (int socket, struct sockaddr *inetaddr, int addrlen)
 Connect a network socket. More...
 
int dlp_sockclose (int socket)
 Close a network socket. More...
 
int dlp_sockblock (int socket)
 Set a network socket to blocking mode. More...
 
int dlp_socknoblock (int socket)
 Set a network socket to non-blocking mode. More...
 
int dlp_noblockcheck (void)
 Check if socket action would have blocked. More...
 
int dlp_setsocktimeo (int socket, int timeout)
 Set socket I/O timeout. More...
 
int dlp_setioalarm (int timeout)
 Set a network I/O real time alarm. More...
 
int dlp_getaddrinfo (char *nodename, char *nodeport, struct sockaddr *addr, size_t *addrlen)
 Resolve IP address and prepare paramters for connect() More...
 
int dlp_openfile (const char *filename, char perm)
 Open a file stream. More...
 
const char * dlp_strerror (void)
 Return a description of the last system error. More...
 
int64_t dlp_time (void)
 Determine the current system time. More...
 
void dlp_usleep (unsigned long int useconds)
 Sleep for a specified number of microseconds. More...
 
int dlp_genclientid (char *progname, char *clientid, size_t maxsize)
 Generate a DataLink client ID from system & process information. More...
 

Detailed Description

:

Platform specific headers. This file provides a basic level of platform portability.

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/

Written by Chad Trabant, IRIS Data Management Center

modified: 2008.193

Function Documentation

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.

Parameters
prognameName of program, usually argv[0]
clientidGenerated client ID string will be written to this string
maxsizeMaximum bytes to write to clientid string.
Returns
the number of charaters written to clientid on success and -1 on error.
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.

Parameters
nodenameHostname to resolve
nodeportPort number to connect to
addrReturned struct sockaddr for connect()
addrlenReturned length of addr
Returns
0 on success and non-zero on error.
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.

Returns
-1 on error and 0 on success (meaning no data for a non-blocking socket).
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.

Parameters
filenameFile to open
permPermission flag
Returns
The return value of open(), generally this is a positive file descriptor on success and -1 on error.
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.

Parameters
timeoutAlarm timeout in seconds
Returns
-1 on error and 0 on success.
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.

Parameters
socketNetwork socket descriptor
timeoutAlarm timeout in seconds
Returns
-1 on error, 0 when not possible and 1 on success.
int dlp_sockblock ( int  socket)

Set a network socket to blocking mode.

Set a network socket to blocking mode.

Parameters
socketNetwork socket descriptor
Returns
-1 on errors and 0 on success.
int dlp_sockclose ( int  socket)

Close a network socket.

Close a network socket.

Parameters
socketNetwork socket descriptor
Returns
-1 on errors and 0 on success.
int dlp_sockconnect ( int  socket,
struct sockaddr *  inetaddr,
int  addrlen 
)

Connect a network socket.

Connect a network socket and perform error checking.

Parameters
socketNetwork socket descriptor
inetaddrThe struct sockaddr, passed to connect()
addrlenLength of inetaddr, passed to connect()
Returns
-1 on errors and 0 on success.
int dlp_socknoblock ( int  socket)

Set a network socket to non-blocking mode.

Set a network socket to non-blocking mode.

Parameters
socketNetwork socket descriptor
Returns
-1 on errors and 0 on success.
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.

Returns
-1 on errors and 0 on success.
const char* dlp_strerror ( void  )

Return a description of the last system error.

Returns
A description of the last system error, in the case of Win32 this will be the last Windows Sockets 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.

Returns
Current time as a dltime_t value.
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.

Parameters
usecondsMicroseconds to sleep.