Files | |
file | socket_lib.c |
This is the implementation of the Socket Library. | |
file | socket_lib.h |
This is the header for the Socket Library. | |
Defines | |
#define | SOCKET_LIB_LOG_BUFF_SIZE 200 |
#define | SOCKET_LIB_NAME "socket_lib" |
#define | SOCKET_LIB_LOG_FILE "socket_lib.log" |
#define | SOCKET_LOGMESSAGE(string, location) |
Functions | |
int | accept_connect (int sock) |
This function calls the accept function with additional logging. | |
int | create_connect (struct in_addr *ipaddr, short port) |
Allows a client to establish a TCP connection with the supplied IP address and port. | |
int | create_serv_socket (int port, int queue_len) |
This function creates a server socket by binding and listening on the supplied port. | |
int | safe_sock_send (int sock, void *send_buff, unsigned int send_len, unsigned int timeout) |
Allows data to be sent safely over the network without fear of the program terminating. | |
int | safe_sock_recv (int sock, void *recv_buff, unsigned int recv_len, unsigned int timeout) |
Allows data to be received over the network without having to manually check that all the data was received. |
Many of today's applications require sending and receiving messages over a network. In order to make this task more programmer-friendly, I developed a component that provides an interface for the most common network functions. The component sends and receives data over network sockets using TCP in the transport layer. TCP is commonly used among network applications and provides the reliability and speed required for most applications.
|
|
|
|
|
|
|
Value: logmessage(string, location ,\ SOCKET_LIB_NAME, SOCKET_LIB_LOG_FILE, __FILE__, __LINE__,\ __FUNCTION__); |
|
This function calls the accept function with additional logging. A programmer can use this function to accept client connections on the new server port. This function uses the same algorithm as the accept function call with additional logging on the connecting client.
|
|
Allows a client to establish a TCP connection with the supplied IP address and port. This function can be used to establish a TCP connection to a server listening on a specified port.
|
|
This function creates a server socket by binding and listening on the supplied port. One of the more common network tasks is creating a server socket that binds and listens for activity on a specified port. This function accomplishes this task for the user. By default this function binds the port on all available network interfaces.
|
|
Allows data to be received over the network without having to manually check that all the data was received. In order to receive data over an established TCP connection, it is important that the data be transfered in a manner that is safe for the calling process and ensures the transfer occurred. The normal network receive function causes the user to make multiple function calls or wait indefinitely. The following functions provide protection from these problems by blocking signals and creating timeouts.
|
|
Allows data to be sent safely over the network without fear of the program terminating. In order to send data over an established TCP connection, it is important that the data be transfered in a manner that is safe for the calling process and ensures the transfer occurred. When a programmer uses the normal network send function, the calling process is terminated if the process tries to send data over a socket that is closed. This function provides protection from this by blocking signals and creating timeouts.
|