Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy

 Receiving Data

The recv function is declared in the header file sys/socket.h. If your flags argument is zero, you can just as well use read instead of recv; see I/O Primitives.

— Function: int recv (int socket, void *buffer, size_t size, int flags)

The recv function is like read, but with the additional flags flags. The possible values of flags are described in Socket Data Options.

If nonblocking mode is set for socket, and no data are available to be read, recv fails immediately rather than waiting. See File Status Flags, for information about nonblocking mode.

This function returns the number of bytes received, or -1 on failure. The following errno error conditions are defined for this function:

The socket argument is not a valid file descriptor.
The descriptor socket is not a socket.
Nonblocking mode has been set on the socket, and the read operation would block. (Normally, recv blocks until there is input available to be read.)
The operation was interrupted by a signal before any data was read. See Interrupted Primitives.
You never connected this socket.

This function is defined as a cancellation point in multi-threaded programs, so one has to be prepared for this and make sure that allocated resources (like memory, files descriptors, semaphores or whatever) are freed even if the thread is canceled.

  Published under the terms of the GNU General Public License Design by Interspire