Recv

From Spectrum
Revision as of 20:58, 19 June 2008 by Winston (talk | contribs) (New page: '''recv (HLCALL 0x3E15)''' - receive data from a connected socket == Synopsis == ''Assembly language'' ld a, (sock_fd) ld de, BUFFER_ADDR ld bc, BUFFER_SIZE ld hl, RECV call HLCALL...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

recv (HLCALL 0x3E15) - receive data from a connected socket

Synopsis

Assembly language

ld a, (sock_fd)
ld de, BUFFER_ADDR
ld bc, BUFFER_SIZE
ld hl, RECV
call HLCALL

C

#include <sys/types.h>
#include <sys/socket.h>

ssize_t recv(int sockfd, void *buf, size_t len, int flags);

Description

The recv call is used only on a connected socket - a SOCK_STREAM socket that has been accepted with accept() or connected to with connect(). The recv() call receives up to len bytes of data from the socket specified by sockfd, copying it to the buffer specified by the memory address buf. In the current implementation, the flags parameter is not used and should be set to 0.

The assembly language function copies data from the socket file descriptor specified in the A register to the memory address pointed to by the DE register pair, up to the number of bytes specified in the BC register pair.

The recv call blocks until data is ready on the socket. If blocking must be avoided, the socket can be checked for ready data using one of the poll routines before recv is called.

Return values

On success, the C routine returns the number of bytes received from the socket. On error, it returns -1.

On success, the assembly language routine returns the number of bytes received in the BC register pair. On error, the carry flag is set and A contains the error number.