liblogging: socketsUnix.c File Reference

Main Page | Compound List | File List | Compound Members | File Members | Related Pages

# socketsUnix.c File Reference

Socket layer/driver for Unix. More...

`#include <sys/fcntl.h>`
`#include <sys/types.h>`
`#include <sys/time.h>`
`#include <sys/socket.h>`
`#include <sys/un.h>`
`#include <sys/select.h>`
`#include <unistd.h>`
`#include <netinet/in.h>`
`#include <netdb.h>`
`#include <errno.h>`

## Functions
srRetVal | sbSockLayerInit (int bInitOSStack)
| Global Layer initialization.
srRetVal | sbSockLayerExit (int bExitOSStack)
| Global Layer destructor.
sbSockObj * | sbSockInit (void)
| Constructor for STREAM sockets, only.
sbSockObj * | sbSockInitEx (int iAF, int iSockType)
| Alternate Constructur.
srRetVal | sbSockClosesocket (sbSockObj *pThis)
| Close a socket.
int | sbSockSelect (struct sbSockObject *pThis, int iTimOutSecs, int iTimOutMSecs)
| Wrapper for the socket select call on a single socket.
int | sbSockSelectMulti (srSock_fd_set *fdsetRD, srSock_fd_set *fdsetWR, int iTimOutSecs, int iTimOutMSecs, int iHighestDesc)
| Wrapper for the socket select call on a fd_set structure.
int | sbSockReceive (struct sbSockObject *pThis, char *pszBuf, int iLen)
int | sbSockSend (struct sbSockObject *pThis, const char *pszBuf, int iLen)
srRetVal | sbSockConnectoToHost (sbSockObj *pThis, char *pszHost, int iPort)
| Connect a socket to a remote host.
srRetVal | sbSockAccept (sbSockObj *pThis, sbSockObj *pNew, struct sockaddr *sa, int *iSizeSA)
| Wrapper for the socket accept() call.
srRetVal | sbSockListen (sbSockObj *pThis)
| Wrapper for the socket listen() call.
srRetVal | sbSockSetNonblocking (sbSockObj *pThis)
| Set the socket to nonblocking state.
srRetVal | sbSockBind (sbSockObj *pThis, char *pszHost, int iPort)
| Bind a socket to the provided address.
srRetVal | sbSock_gethostname (char **psz)
| Wrapper for gethostname().

## Detailed Description

Socket layer/driver for Unix.

This is the low-level socket layer for Unix. This file is included from sockets::c. Please note that this file implements Unix Domain Sockets if that feature is enabled. This is not done in sockets.c, as this obviously is an Unix-only thing.

Author:
  Rainer Gerhards <rgerhards@adiscon.com>

  Devin Kowatch <devink@sdsc.edu>

Date:
  2003-08-04 rgerhards: inital version created

  2003-08-04 devink: initial UNIX port

  2003-08-05 rgerhards: Changed to be a lower layer to the generic sockets.c.

  2003-08-05 devink: applied changes to compile under Solaris. AIX also works well.

  2003-09-29 rgerhards: upgraded this module to support Unix Domain Sockets.

Copyright 2002-2003 Rainer Gerhards and Adiscon GmbH. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Adiscon GmbH or Rainer Gerhards nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## Function Documentation

srRetVal sbSock_gethostname | ( | char ** | psz | ) |

  | Wrapper for gethostname(). Parameters:
  psz | Pointer to Pointer to hostname. Must not be NULL. On return, this pointer will refer to a newly allocated buffer containing the hostname. This buffer must be free()ed by the caller!

srRetVal sbSockBind | ( | sbSockObj * | pThis,
|  | char * | pszHost,
|  | int | iPort
| ) |

| Bind a socket to the provided address. sorry, other modes currently not supported Todo: implement!

srRetVal sbSockConnectoToHost | ( | sbSockObj * | pThis,
|  | char * | pszHost,
|  | int | iPort
| ) |

  | Connect a socket to a remote host. Parameters:
  pszHost | Name or IP address of host to connect to
  iPort | Port to connect to

sbSockObj* sbSockInit | ( | void |  | ) |

  | Constructor for STREAM sockets, only. Return values:
  Returns | a pointer to the new instance or NULL, if it could not be created.

sbSockObj* sbSockInitEx | ( | int | af,
|  | int | iSockType
| ) |

| Alternate Constructur. Socket TYPE (STREAM/DGRAM) can be specified

srRetVal sbSockLayerExit | ( | int | bExitOSStack | ) |

  | Global Layer destructor. Call this only once at the end of the application. All sockets must be destroyed before calling this method. Parameters:
  bExitOSStack | Specifies if the library should shut down the operating system socket stack. If 1, it shuts it down, if 0, it does not. Set this to 0 if you integrate this lib into an app that otherwise shuts down the OS socket lib itself.

srRetVal sbSockLayerInit | ( | int | bInitOSStack | ) |

  | Global Layer initialization. Should be called only once per application. This will do all housekeeping necessary to use the layer. DO NOT CALL ANY OTHER METHODS BEFORE THIS ONE HAS BEEN CALLED! They will probably fail! Parameters:
  bInitOSStack | Specifies if the library should initialize the operating system socket stack. If 1, it initializes it, if 0, it does not. Set this to 0 if you integrate this lib into an app that otherwise initializes the socket lib itself.

int sbSockSelect | ( | struct sbSockObject * | pThis,
|  | int | iTimOutSecs,
|  | int | iTimOutMSecs
| ) |

  | Wrapper for the socket select call on a single socket. Parameters:
  iTimOutSecs | Seconds until timeout. -1 means indefinite blocking.
  iTimOutMSecs | Milliseconds until timeout.
  Return values:
  Value | returned by select.

int sbSockSelectMulti | ( | srSock_fd_set * | fdsetRD,
|  | srSock_fd_set * | fdsetWR,
|  | int | iTimOutSecs,
|  | int | iTimOutMSecs,
|  | int | iHighestDesc
| ) |

  | Wrapper for the socket select call on a fd_set structure. Parameters:
  iTimOutSecs | Seconds until timeout. -1 means indefinite blocking.
  iTimOutMSecs | Milliseconds until timeout.
  iHighestDesc | [*NIX ONLY!] The highest file descriptor in any of the fd_sets.
  Return values:
  Value | returned by select.