06.08.2013 Views

pSOSystem System Calls - Read

pSOSystem System Calls - Read

pSOSystem System Calls - Read

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

pNA+ <strong>System</strong> <strong>Calls</strong> recv<br />

recv Receives data from a socket.<br />

#include <br />

long recv(<br />

int s, /* socket descriptor */<br />

char *buf, /* packet */<br />

int len, /* packet length */<br />

int flags /* packet attributes */<br />

)<br />

Description<br />

Arguments<br />

The recv() system call is used to receive data from the specified socket. The<br />

behavior of this system call depends on the socket type, as described under<br />

“Arguments.”<br />

The recv() system call returns the number of bytes received, and this value should<br />

always be checked because this is the only way to detect the actual number of data<br />

bytes stored in the user buffer.<br />

Applications can use this call to receive messages from the pNA+ network manager<br />

in a linked list of mblks (message blocks) by setting the MSG_RAWMEM flag. Using<br />

mblks eliminates the data copy performed in the pNA+ network manager during the<br />

data transfer between the application and the pNA+ network manager.<br />

s Specifies the socket from which data is received. s can be a stream,<br />

a datagram, or a raw socket.<br />

If s is a stream socket, recv() copies whatever data is available at<br />

the socket to the user buffer and returns. recv() never copies more<br />

than len bytes of data to the user buffer, but it can copy less, if less<br />

than len bytes are available. Unless ioctl() was used to mark the<br />

socket non-blocking, recv() blocks the caller if no data is available<br />

at the socket. The caller is unblocked when data is received. If the<br />

socket has been marked non-blocking, recv() returns immediately<br />

whether or not data is received.<br />

<strong>pSO<strong>System</strong></strong> <strong>System</strong> <strong>Calls</strong> 4-45<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!