[Rlib] C ++ for socket classes

Source: Internet
Author: User

For more information about the source code, see rlib open-source projects.

The following is the header file of rlib1.x:

Namespace system {namespace net {// <summary> // provides standard access to Winsock /// </Summary> class export sockets {protected: Socket m_socket; sockaddr_in m_addr; exception * m_error; public: Sockets (socket S = invalid_socket );~ Sockets (); rlib_classnewdel; public: /// <summary> /// method allows you to obtain the socket for more operations // You can inherit and expand the functions of the sockets class /// </Summary> Operator socket (); /// <summary> /// set the sending timeout /// </Summary> bool setsndtimeo (INT timeout ); /// <summary> /// obtain the sending buffer /// </Summary> int getsndbuf (); /// <summary> /// set the receiving timeout /// </Summary> bool setrcvtimeo (INT timeout ); /// <summary> /// obtain the receiving buffer /// </Summary> int getrcvbuf (); /// <summary> /// closes an existing socket /// </Summary> bool close (); /// <summary> /// establishes a connection to a specified socket // </Summary> bool connect (char * Host, unsigned int host_len, u_short port ); /// <summary> /// sends data on a connected socket // when an error occurs, size is used to receive the sent length // </Summary> bool send (char * data, int * size ); /// <summary> // specify es data from a connected or bound socket // when an error occurs, size is used to receive received length // </Summary> int recvex (char * Buf, int * size ); /// <summary> /// es data from a connected or bound socket // This method does not guarantee that the specified size is received. /// </Summary> int Recv (char * Buf, int size); // <summary> // associates a local address with a socket // </Summary> int BIND (ulong ADDR, u_short port ); /// <summary> /// associates a local address with a socket // The method is bound to all addresses /// </Summary> int BIND (u_short port ); /// <summary> // places a socket a state where it is listening for an incoming connection // </Summary> int listen (INT backlog = somaxconn ); /// <summary> /// permits an incoming connection attempt on a socket // an optional pointer to a buffer that matches es the address of the connecting entity, /// as known to the communications layer. /// </Summary> sockets * accept (sockaddr_in * ADDR = NULL, int * addrlen = NULL ); /// <summary> /// disables sends or distinct es on a socket // </Summary> int Shutdown (INT how = sd_both ); /// <summary> /// obtain the wincock exception information // This method is only provided to the Instance Object /// </Summary> exception * getlastexception (); /// <summary> /// obtain a value indicating whether a connection has been established with the Internet. /// </Summary> bool isconnect; public: /// <summary> /// obtain the name of the Local Computer /// </Summary> static bool getlocalhost (char * Host, int hostlen ); /// <summary> /// obtain the address of the Local Computer /// </Summary> static bool getlocalipaddress (char * Host, paddrinfoa * addrinfo ); /// <summary> /// release addrinfo obtained by getlocalipaddress /// </Summary> static void freelocalipaddress (paddrinfoa * addrinfo ); /// <summary> /// converts a string containing an (IPv4) internet Protocol dotted address into a proper address for the in_addr structure // </Summary> static unsigned long limit 4stringtoaddress (const char * CP ); /// <summary> /// converts an (IPv4) internet network address into a string in Internet standard dotted format // </Summary> static char * ipv4addresstostring (in_addr in ); /// <summary> /// get the error description of wincock /// </Summary> static bool getlasterror (lpvoid buffer, size_t size, int err = 0 ); /// <summary >/// when you no longer use Winsock, calling this method will release the network module memory /// </Summary> static void dispose ();};}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.