Select Network Programming

Network Programming learning mode, there are select, poll, epoll, etc., tests are three ways to test the network connection.

/*


*/


#ifndef _CCNET_H
#define _CCNET_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>


File @ //
// @ Brief network package handler

/ **
tcp connection function * @brief with Timeout (microseconds) of
* @param host: connection to the host name can not be NULL
* @param Port: connection to the host listening port
* @param timeout: maximum timeout (subtle) of pointers, not NULL, the successful connection timeout is set to the remaining time
* @param name: the name of the connection module
* @return -1 connection failure or timeout
socket * @return socket connection success
* /
int CCConnectO (const char * Host , int port, int * timeout, const char * name);

/ **
* @brief Socket read with timeout (microseconds) of
* @param sock: socket attached
* @param buf: reading space
* @param len: reading the maximum length
* @param timeout: maximum timeout (subtle) pointer is not NULL, the function returns the timeout is set to the remaining time
* @param name: the name of the connection module
* @return -1 read failed
number of characters actually read @return *
* /
int CCReadO (int sock, void * buf, ssize_t len, int * timeout, const char * name);

/ **
Socket @brief with timeout * (microsecond) read operation until the read contents appeared stop string, or the length len read, or timeout.
* @Param sock: socket attached
* @param buf: reading into the space
* @param len: reading the maximum length
* @param timeout: maximum timeout (subtle) pointer is not NULL, the function returns a timeout It will be set to the remaining time
* @param name: the name of the connection module
* @param stop: stop the string occurs when the content read, stop reading
failure * @return -1 reading
the number of characters actually read @return *
* /
int CCReadOS (our sock int, void * buf, len an ssize_t, timeout int *, const char * name,
const char * STOP);

/ **
* @brief Socket with timeout (microseconds) writes
* @param sock: socket attached
* @param buf: a space to write
* @param len: the maximum length to be written
* @param timeout: maximum timeout (subtle) pointer is not NULL, the function returns the timeout is set to the remaining time
* @param name: the name of the connection module
* @return -1 fails to read
the number of the actual written characters * @return
* /
int CCWriteO (our sock int, void * buf, len an ssize_t, timeout int *,
const char * name);

/ **
* @brief Close Socket
* @param FD: connected Socket
* @return -1 off failure
* @return 0 Close success
* /
int CCClose (int FD);

/ **
* @brief open tcp listening port
* @param port: the port
* @param queue: listen queue length
* @return -1 failure
* @return successful return opening listens FD
* /
int CCTcpListen (const char * Host, int port, int queue);

#endif // _CCNET_H
/ * vim: create noet: * /

Guess you like

Origin www.cnblogs.com/cyblogs/p/11295568.html