Macros | Functions | Variables
Socket.c File Reference

Socket related functions. More...

#include "Socket.h"
#include "Log.h"
#include "SocketBuffer.h"
#include "Messages.h"
#include "StackTrace.h"
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include "Heap.h"
Include dependency graph for Socket.c:

Go to the source code of this file.

Macros

#define ADDRLEN   INET6_ADDRSTRLEN+1
 
#define PORTLEN   10
 

Functions

int isReady (int socket, fd_set *read_set, fd_set *write_set)
 
int Socket_abortWrite (int socket)
 
void Socket_addPendingWrite (int socket)
 
int Socket_addSocket (int newSd)
 
void Socket_clearPendingWrite (int socket)
 
void Socket_close (int socket)
 
int Socket_close_only (int socket)
 
int Socket_continueWrite (int socket)
 
int Socket_continueWrites (fd_set *pwset)
 
int Socket_error (char *aString, int sock)
 
char * Socket_getaddrname (struct sockaddr *sa, int sock)
 
int Socket_getch (int socket, char *c)
 
char * Socket_getdata (int socket, size_t bytes, size_t *actual_len, int *rc)
 
char * Socket_getpeer (int sock)
 
int Socket_getReadySocket (int more_work, struct timeval *tp, mutex_type mutex)
 
int Socket_new (const char *addr, size_t addr_len, int port, int *sock)
 
int Socket_noPendingWrites (int socket)
 
void Socket_outInitialize (void)
 
void Socket_outTerminate (void)
 
int Socket_putdatas (int socket, char *buf0, size_t buf0len, PacketBuffers bufs)
 
int Socket_setnonblocking (int sock)
 
void Socket_setWriteCompleteCallback (Socket_writeComplete *mywritecomplete)
 
int Socket_writev (int socket, iobuf *iovecs, int count, unsigned long *bytes)
 

Variables

Sockets mod_s
 
static Socket_writeCompletewritecomplete = NULL
 
static fd_set wset
 

Detailed Description

Socket related functions.

Some other related functions are in the SocketBuffer module

Definition in file Socket.c.

Macro Definition Documentation

#define ADDRLEN   INET6_ADDRSTRLEN+1
#define PORTLEN   10

Function Documentation

int isReady ( int  socket,
fd_set *  read_set,
fd_set *  write_set 
)

Don't accept work from a client unless it is accepting work back, i.e. its socket is writeable this seems like a reasonable form of flow control, and practically, seems to work.

Parameters
socketthe socket to check
read_setthe socket read set (see select doc)
write_setthe socket write set (see select doc)
Returns
boolean - is the socket ready to go?

Definition at line 221 of file Socket.c.

int Socket_abortWrite ( int  socket)

Continue an outstanding write for a particular socket

Parameters
socketthat socket
Returns
completion code: 0=incomplete, 1=complete, -1=socket error

Definition at line 950 of file Socket.c.

void Socket_addPendingWrite ( int  socket)

Add a socket to the pending write list, so that it is checked for writing in select. This is used in connect processing when the TCP connect is incomplete, as we need to check the socket for both ready to read and write states.

Parameters
socketthe socket to add

Definition at line 577 of file Socket.c.

int Socket_addSocket ( int  newSd)

Add a socket to the list of socket to check with select

Parameters
newSdthe new socket to add

Definition at line 169 of file Socket.c.

void Socket_clearPendingWrite ( int  socket)

Clear a socket from the pending write list - if one was added with Socket_addPendingWrite

Parameters
socketthe socket to remove

Definition at line 587 of file Socket.c.

void Socket_close ( int  socket)

Close a socket and remove it from the select list.

Parameters
socketthe socket to close
Returns
completion code

Definition at line 627 of file Socket.c.

int Socket_close_only ( int  socket)

Close a socket without removing it from the select list.

Parameters
socketthe socket to close
Returns
completion code

Definition at line 599 of file Socket.c.

int Socket_continueWrite ( int  socket)

Continue an outstanding write for a particular socket

Parameters
socketthat socket
Returns
completion code: 0=incomplete, 1=complete, -1=socket error

Definition at line 864 of file Socket.c.

int Socket_continueWrites ( fd_set *  pwset)

Continue any outstanding writes for a socket set

Parameters
pwsetthe set of sockets
Returns
completion code

Definition at line 983 of file Socket.c.

int Socket_error ( char *  aString,
int  sock 
)

Gets the specific error corresponding to SOCKET_ERROR

Parameters
aStringthe function that was being used when the error occurred
sockthe socket on which the error occurred
Returns
the specific TCP error code

Definition at line 101 of file Socket.c.

char * Socket_getaddrname ( struct sockaddr *  sa,
int  sock 
)

Convert a numeric address to character string

Parameters
sasocket numerical address
socksocket
Returns
the peer information

maximum length of the address string

maximum length of the port string

Definition at line 1023 of file Socket.c.

int Socket_getch ( int  socket,
char *  c 
)

Reads one byte from a socket

Parameters
socketthe socket to read from
cthe character read, returned
Returns
completion code

Definition at line 332 of file Socket.c.

char* Socket_getdata ( int  socket,
size_t  bytes,
size_t *  actual_len,
int *  rc 
)

Attempts to read a number of bytes from a socket, non-blocking. If a previous read did not finish, then retrieve that data.

Parameters
socketthe socket to read from
bytesthe number of bytes to read
actual_lenthe actual number of bytes read
Returns
completion code

Definition at line 370 of file Socket.c.

char* Socket_getpeer ( int  sock)

Get information about the other end connected to a socket

Parameters
sockthe socket to inquire on
Returns
the peer information

Definition at line 1058 of file Socket.c.

int Socket_getReadySocket ( int  more_work,
struct timeval *  tp,
mutex_type  mutex 
)

Returns the next socket ready for communications as indicated by select

Parameters
more_workflag to indicate more work is waiting, and thus a timeout value of 0 should be used for the select
tpthe timeout to be used for the select, unless overridden
Returns
the socket next ready, or 0 if none is ready

Definition at line 242 of file Socket.c.

int Socket_new ( const char *  addr,
size_t  addr_len,
int  port,
int *  sock 
)

Create a new socket and TCP connect to an address/port

Parameters
addrthe address string
portthe TCP port
sockreturns the new socket
timeoutthe timeout in milliseconds
Returns
completion code

Definition at line 671 of file Socket.c.

int Socket_noPendingWrites ( int  socket)

Indicate whether any data is pending outbound for a socket.

Returns
boolean - true == data pending.

Definition at line 417 of file Socket.c.

void Socket_outInitialize ( void  )

Initialize the socket module

Definition at line 122 of file Socket.c.

void Socket_outTerminate ( void  )

Terminate the socket module

Definition at line 151 of file Socket.c.

int Socket_putdatas ( int  socket,
char *  buf0,
size_t  buf0len,
PacketBuffers  bufs 
)

Attempts to write a series of buffers to a socket in one system call so that they are sent as one packet.

Parameters
socketthe socket to write to
buf0the first buffer
buf0lenthe length of data in the first buffer
countnumber of buffers
buffersan array of buffers to write
buflensan array of corresponding buffer lengths
Returns
completion code, especially TCPSOCKET_INTERRUPTED

Definition at line 505 of file Socket.c.

int Socket_setnonblocking ( int  sock)

Set a socket non-blocking, OS independently

Parameters
sockthe socket to set non-blocking
Returns
TCP call error code

Definition at line 74 of file Socket.c.

void Socket_setWriteCompleteCallback ( Socket_writeComplete mywritecomplete)

Definition at line 852 of file Socket.c.

int Socket_writev ( int  socket,
iobuf iovecs,
int  count,
unsigned long *  bytes 
)

Attempts to write a series of iovec buffers to a socket in one system call so that they are sent as one packet.

Parameters
socketthe socket to write to
iovecsan array of buffers to write
countnumber of buffers in iovecs
bytesnumber of bytes actually written returned
Returns
completion code, especially TCPSOCKET_INTERRUPTED

Definition at line 433 of file Socket.c.

Variable Documentation

Sockets mod_s

Structure to hold all socket data for this module

Definition at line 66 of file Socket.c.

Socket_writeComplete* writecomplete = NULL
static

Definition at line 850 of file Socket.c.

fd_set wset
static

Definition at line 67 of file Socket.c.



plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:49