#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include "mutex_type.h"
#include "LinkedList.h"
Go to the source code of this file.
|
void | Socket_addPendingWrite (int socket) |
|
void | Socket_clearPendingWrite (int socket) |
|
void | Socket_close (int socket) |
|
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 *socket) |
|
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) |
|
void | Socket_setWriteCompleteCallback (Socket_writeComplete *) |
|
#define INET6_ADDRSTRLEN 46 /** only needed for gcc/cygwin on windows */ |
#define max |
( |
|
A, |
|
|
|
B |
|
) |
| ( (A) > (B) ? (A):(B)) |
error in socket operation
Definition at line 76 of file Socket.h.
#define TCPSOCKET_COMPLETE 0 |
socket operation completed successfully
Definition at line 73 of file Socket.h.
#define TCPSOCKET_INTERRUPTED -22 |
must be the same as SOCKETBUFFER_INTERRUPTED
Definition at line 79 of file Socket.h.
typedef void Socket_writeComplete(int socket, int rc) |
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
-
Definition at line 577 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
-
socket | the 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
-
socket | the socket to close |
- Returns
- completion code
Definition at line 627 of file Socket.c.
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
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
-
socket | the socket to read from |
bytes | the number of bytes to read |
actual_len | the 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
-
sock | the 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_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
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
-
addr | the address string |
port | the TCP port |
sock | returns the new socket |
timeout | the 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
-
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
Definition at line 505 of file Socket.c.