From Spectrum
Jump to navigation Jump to search

poll - HLCALL 0x3E1E - poll an array of sockets

pollfd, poll_fd - HLCALL 0x3E24 - poll a single socket

pollall - HLCALL 0x3E21 - poll all open sockets


Assembly language


    ld de, addr_socklist      ; pointer to a list of sockets to poll
    ld b, num_socks           ; number of sockets in the list
    ld hl, POLL
    call HLCALL               ; returns socket in A, flags in B


    ld a, (v_sockfd)          ; socket file descriptor
    ld hl, POLLFD
    call HLCALL               ; zero flag is set if sockfd is not ready. Flags returned in C


    ld hl, POLLALL
    call HLCALL               ; zero flag set if none ready, else A contains fd and C contains flags


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

    char poll_fd(int sockfd);
    int pollall(struct pollfd *p);


poll, pollall and pollfd check the state of sockets, and immediately return information on the socket's state. The poll routine (TO DO: C library POSIX compatible implementation) checks the sockets listed in an array. The pollfd (asm) and poll_fd (C) routines report the state of an individual socket. The pollall function polls all open sockets, reporting the status of the first socket found to have significant status.

The pollall routine takes a struct pollfd pointer as its parameter, and fills the revents member of the structure with the status flags, and returns the socket file descriptor as its return code. The pollfd (C: poll_fd) function returns a single byte containing a bit field that is defined in the same manner as the revents field of the struct pollfd.

The events/revents bit field is defined as follows, and is identical for the asm and C functions:

#define POLLCON     1        /* a remote host connected to the listening socket (not POSIX) */
#define POLLHUP     2        /* the remote host closed the connection */
#define POLLIN      4        /* data is ready to be received */
#define POLLNVAL    128      /* error occurred during polling */

Return values

The assembly language interface returns with the zero flag set for all of the poll functions if no socket that was polled had any significant status. When a socket has significant status, poll and pollall return the socket descriptor in A, and reset the zero flag. The poll routine returns the flags in B. For pollall and pollfd, the flags are returned in C.

For the C functions, pollall returns the socket descriptor, and fills the passed pollfd structure. The poll_fd function returns the flags if the socket polled has significant status, otherwise, it returns 0.