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:

Defines

#define ADDRLEN   INET6_ADDRSTRLEN+1
#define PORTLEN   10

Functions

int Socket_setnonblocking (int sock)
 Set a socket non-blocking, OS independently.
int Socket_error (char *aString, int sock)
 Gets the specific error corresponding to SOCKET_ERROR.
int Socket_addSocket (int newSd)
 Add a socket to the list of socket to check with select.
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.
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.
int Socket_close_only (int socket)
 Close a socket without removing it from the select list.
int Socket_continueWrite (int socket)
 Continue an outstanding write for a particular socket.
int Socket_continueWrites (fd_set *pwset)
 Continue any outstanding writes for a socket set.
char * Socket_getaddrname (struct sockaddr *sa, int sock)
 Convert a numeric address to character string.
void Socket_outInitialize (void)
 Initialize the socket module.
void Socket_outTerminate (void)
 Terminate the socket module.
int Socket_getReadySocket (int more_work, struct timeval *tp)
 Returns the next socket ready for communications as indicated by select.
int Socket_getch (int socket, char *c)
 Reads one byte from a socket.
char * Socket_getdata (int socket, size_t bytes, size_t *actual_len)
 Attempts to read a number of bytes from a socket, non-blocking.
int Socket_noPendingWrites (int socket)
 Indicate whether any data is pending outbound for a socket.
int Socket_putdatas (int socket, char *buf0, size_t buf0len, int count, char **buffers, size_t *buflens, int *frees)
 Attempts to write a series of buffers to a socket in *one* system call so that they are sent as one packet.
void Socket_addPendingWrite (int socket)
 Add a socket to the pending write list, so that it is checked for writing in select.
void Socket_clearPendingWrite (int socket)
 Clear a socket from the pending write list - if one was added with Socket_addPendingWrite.
void Socket_close (int socket)
 Close a socket and remove it from the select list.
int Socket_new (char *addr, int port, int *sock)
 Create a new socket and TCP connect to an address/port.
void Socket_setWriteCompleteCallback (Socket_writeComplete *mywritecomplete)
char * Socket_getpeer (int sock)
 Get information about the other end connected to a socket.

Variables

Sockets s
 Structure to hold all socket data for the module.
static fd_set wset
static Socket_writeComplete * writecomplete = NULL

Detailed Description

Socket related functions.

Some other related functions are in the SocketBuffer module


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:
socket the socket to check
read_set the socket read set (see select doc)
write_set the socket write set (see select doc)
Returns:
boolean - is the socket ready to go?

Here is the call graph for this function:

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:
socket the socket to add
int Socket_addSocket ( int  newSd  ) 

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

Parameters:
newSd the new socket to add

Here is the call graph for this function:

void Socket_clearPendingWrite ( int  socket  ) 

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

Parameters:
socket the socket to remove
void Socket_close ( int  socket  ) 

Close a socket and remove it from the select list.

Parameters:
socket the socket to close
Returns:
completion code

Here is the call graph for this function:

int Socket_close_only ( int  socket  ) 

Close a socket without removing it from the select list.

Parameters:
socket the socket to close
Returns:
completion code

Here is the call graph for this function:

int Socket_continueWrite ( int  socket  ) 

Continue an outstanding write for a particular socket.

Parameters:
socket that socket
Returns:
completion code

Here is the call graph for this function:

int Socket_continueWrites ( fd_set *  pwset  ) 

Continue any outstanding writes for a socket set.

Parameters:
pwset the set of sockets
Returns:
completion code

Here is the call graph for this function:

int Socket_error ( char *  aString,
int  sock 
)

Gets the specific error corresponding to SOCKET_ERROR.

Parameters:
aString the function that was being used when the error occurred
sock the socket on which the error occurred
Returns:
the specific TCP error code

Here is the call graph for this function:

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

Convert a numeric address to character string.

Parameters:
sa socket numerical address
sock socket
Returns:
the peer information

maximum length of the address string

maximum length of the port string

Here is the call graph for this function:

int Socket_getch ( int  socket,
char *  c 
)

Reads one byte from a socket.

Parameters:
socket the socket to read from
c the character read, returned
Returns:
completion code

Here is the call graph for this function:

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

Attempts to read a number of bytes from a socket, non-blocking.

If a previous read did not finish, then retrieve that data.

Parameters:
socket the socket to read from
bytes the number of bytes to read
actual_len the actual number of bytes read
Returns:
completion code

Here is the call graph for this function:

char* Socket_getpeer ( int  sock  ) 

Get information about the other end connected to a socket.

Parameters:
sock the socket to inquire on
Returns:
the peer information

Here is the call graph for this function:

int Socket_getReadySocket ( int  more_work,
struct timeval *  tp 
)

Returns the next socket ready for communications as indicated by select.

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

Here is the call graph for this function:

int Socket_new ( char *  addr,
int  port,
int *  sock 
)

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

Parameters:
addr the address string
port the TCP port
sock returns the new socket
Returns:
completion code

Here is the call graph for this function:

int Socket_noPendingWrites ( int  socket  ) 

Indicate whether any data is pending outbound for a socket.

Returns:
boolean - true == data pending.

Here is the call graph for this function:

int Socket_putdatas ( int  socket,
char *  buf0,
size_t  buf0len,
int  count,
char **  buffers,
size_t *  buflens,
int *  frees 
)

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

Parameters:
socket the socket to write to
buf0 the first buffer
buf0len the length of data in the first buffer
count number of buffers
buffers an array of buffers to write
buflens an array of corresponding buffer lengths
Returns:
completion code, especially TCPSOCKET_INTERRUPTED

Here is the call graph for this function:

int Socket_setnonblocking ( int  sock  ) 

Set a socket non-blocking, OS independently.

Parameters:
sock the socket to set non-blocking
Returns:
TCP call error code
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:
socket the socket to write to
iovecs an array of buffers to write
count number of buffers in iovecs
bytes number of bytes actually written returned
Returns:
completion code, especially TCPSOCKET_INTERRUPTED

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Defines

Generated on 26 Oct 2017 for MQTT C Client Libraries Internals by  doxygen 1.6.1