select - Speeding up non-blocking Unix Sockets (C++) -


I have implemented a simple socket wrapper class. It includes a non-intercept function:

  zero socket :: set_on_blocking (consolebull b) {mNonBlocking = b; // square member for reference int opts = fcntl (m_sock, F_GETFL); If (opts & lt; 0) return; If (b) opts | = O_NONBLOCK; And opts & amp; = ~ O_NONBLOCK; FCNTL (M_Sock, F_SEFFL, Opts); }  

There is also a simple get function in the class:

  int socket :: recv (std :: string and) const {char buffer [MAXRECV] ] + 1]; S = ""; Memset (buffer, 0, MAXRECV + 1); Int Status = :: RQV (M_sock, buffer, MaxRCV, 0); If (position == -1) {if (! MNonBlocking) std :: cout & lt; & Lt; "Socket, Error getting Data \ n"; Return 0; } And if (condition == 0) {return 0; } Else {s = buffer; Return status; }}  

In practice, it seems that ~ 15 mills is delayed when the socket: recv () is called. Is this procrastination handy? I have seen some non-blocking examples that use selection (), but can not understand how it can help.

It depends on you how you use sockets if you have multiple sockets And you are checking the data on all those who can be late for the account.

With non-blocking recv you are based on the data that exists there if your application needs to use more than one socket, then to find out if the data is available to everyone , You must continuously pool each socket.

This system is poor for resources because it means that your app is constantly running, whenever there is nothing to do.

You can save as you choose, you basically set your socket, add them to the group and select on the group.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -