ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcbSocket.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  ngcb_pipe_t
 
struct  ngcb_saddr_cache
 

Macros

#define str2str(s1, s2, n)
 
#define ngcbTAG_SUCCESS   "!SUCCESS!\n"
 
#define ngcbTAG_ERROR   "!ERROR!\n"
 
#define ngcbADDR_CACHE_SIZE   8
 

Functions

void ngcbRegisterLock (void(*lock)(void), void(*unlock)(void))
 
void ngcbLock (void)
 
void ngcbUnlock (void)
 
void ngcbIpAddrCache (int flag)
 
int ngcbGetHost (const char *name, char *ipAddr, char *hostName, char *erms)
 
int ngcbGetHostName (char *name, int size)
 
int ngcbGetIpAddr (const char *name, char *ipAddr, char *erms)
 
int ngcbSocketPort (int fd)
 
void ngcbSocketHost (int fd, char *ipAddr)
 
int ngcbSocketWait (int fd, int timeout, char *erms)
 
int ngcbSocketWaitIntr (int fd1, int fd2, int timeout, char *erms)
 
int ngcbSocketPair (int fd[2], int bufferSize, char *erms)
 
int ngcbHostCompare (const char *host1, const char *host2)
 
int ngcbTcpService (const char *service, char *erms)
 
int ngcbTcpAccept (int fd, char *erms)
 
int ngcbTcpConnect (const char *service, char *erms)
 
int ngcbTcpConnectTmo (const char *service, int tmo, char *erms)
 
int ngcbTcpClose (int fd)
 
int ngcbTcpWrite (int fd, const void *buffer, size_t size, char *erms)
 
int ngcbTcpRead (int fd, void *buffer, size_t size, char *erms)
 
void ngcbPipeInit (ngcb_pipe_t *p)
 
int ngcbPipeOpen (const char *cmd, ngcb_pipe_t *p, char *erms)
 
void ngcbPipeClose (ngcb_pipe_t *p)
 
void ngcbPipeError (char *erms, int n, ngcb_pipe_t *p)
 
int ngcbPipeIn (const char *cmd, char *msg, int n)
 
int ngcbAddr (int fd, int board, int addr, int *buffer, int size, char *erms)
 

Detailed Description

Macro Definition Documentation

◆ ngcbADDR_CACHE_SIZE

#define ngcbADDR_CACHE_SIZE   8

Default IP-address cache size

◆ ngcbTAG_ERROR

#define ngcbTAG_ERROR   "!ERROR!\n"

ERROR reply

◆ ngcbTAG_SUCCESS

#define ngcbTAG_SUCCESS   "!SUCCESS!\n"

SUCCESS reply

◆ str2str

#define str2str ( s1,
s2,
n )
Value:
__str2str(s1, s2, n)

Function Documentation

◆ ngcbAddr()

int ngcbAddr ( int fd,
int board,
int addr,
int * buffer,
int size,
char * erms )

Remote address access

◆ ngcbGetHost()

int ngcbGetHost ( const char * name,
char * ipAddr,
char * hostName,
char * erms )

Convert name to ip-address if name is a hostname or converts name to hostname, if name is an ip-address.

◆ ngcbGetHostName()

int ngcbGetHostName ( char * name,
int size )

Returns the host name of the calling host. The maximum length of the name is given by size.

◆ ngcbGetIpAddr()

int ngcbGetIpAddr ( const char * name,
char * ipAddr,
char * erms )

Converts name to an ip-address.

◆ ngcbHostCompare()

int ngcbHostCompare ( const char * host1,
const char * host2 )

Check, whether two hosts are identical. The function returns zero if the comparison was successfull, otherwise a non-zero value is returned.

◆ ngcbIpAddrCache()

void ngcbIpAddrCache ( int flag)

Enable/disable IP-address cache.

◆ ngcbLock()

void ngcbLock ( void )

Lock - using the registered functions

◆ ngcbPipeClose()

void ngcbPipeClose ( ngcb_pipe_t * p)

Close the pipe and terminates the executed process.

◆ ngcbPipeError()

void ngcbPipeError ( char * erms,
int n,
ngcb_pipe_t * p )

Read the stderr output of the executed process up to a length of n-1 characters. The returned error message is then terminated with a null character.

◆ ngcbPipeIn()

int ngcbPipeIn ( const char * cmd,
char * msg,
int n )

Read up to n-1 characters from stdout of cmd, put them to msg and add a terminating NULL character. If an error occurs, stderr is read in the same way and copied to msg. In case of error the function returns (-1), otherwise zero is returned.

◆ ngcbPipeInit()

void ngcbPipeInit ( ngcb_pipe_t * p)

Initialize/reset pipe structure.

◆ ngcbPipeOpen()

int ngcbPipeOpen ( const char * cmd,
ngcb_pipe_t * p,
char * erms )

Execute command as a child process and create a pipe between caller and executed process.

◆ ngcbRegisterLock()

void ngcbRegisterLock ( void(* lock )(void),
void(* unlock )(void) )

Register locking functions

◆ ngcbSocketHost()

void ngcbSocketHost ( int fd,
char * ipAddr )

Returns the peer (remote) ipAddr (as string) associated with a socket.

◆ ngcbSocketPair()

int ngcbSocketPair ( int fd[2],
int bufferSize,
char * erms )

Create a pair of connected UNIX-domain sockets.

◆ ngcbSocketPort()

int ngcbSocketPort ( int fd)

Return the port number associated with a socket. If the socket is not valid zero is returned.

◆ ngcbSocketWait()

int ngcbSocketWait ( int fd,
int timeout,
char * erms )

Wait with timeout (in millisconds) for a socket to become readable. A negative value means no-timeout.

◆ ngcbSocketWaitIntr()

int ngcbSocketWaitIntr ( int fd1,
int fd2,
int timeout,
char * erms )

Waits with timeout (in millisconds) for socket fd1 or fd2 to become readable. A negative value means no-timeout. If a timeout occurs, the value -1 is returned. If socket fd2 becomes readable first, the value -2 is returned (interrupted).

◆ ngcbTcpAccept()

int ngcbTcpAccept ( int fd,
char * erms )

Accept a tcp/ip client connection request and return the client socket.

◆ ngcbTcpClose()

int ngcbTcpClose ( int fd)

Close tcp/ip socket.

◆ ngcbTcpConnect()

int ngcbTcpConnect ( const char * service,
char * erms )

Connect to a tcp/ip socket service specified in the format "host:port". The function returns a client socket descriptor.

◆ ngcbTcpConnectTmo()

int ngcbTcpConnectTmo ( const char * service,
int tmo,
char * erms )

Cnnects to a tcp/ip socket service specified in the format "host:port". The function returns a client socket descriptor. The connect timeout is given in seconds. Zero or a negavitve number falls back to the default connection timeout as provided by the OS.

◆ ngcbTcpRead()

int ngcbTcpRead ( int fd,
void * buffer,
size_t size,
char * erms )

Read size bytes of from tcp/ip socket into buffer.

◆ ngcbTcpService()

int ngcbTcpService ( const char * service,
char * erms )

Open a tcp/ip server socket.

◆ ngcbTcpWrite()

int ngcbTcpWrite ( int fd,
const void * buffer,
size_t size,
char * erms )

Write size bytes of buffer to tcp/ip socket.

◆ ngcbUnlock()

void ngcbUnlock ( void )

Unlock - using the registered functions