| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

write_UDP

#include "sflsock.h"
int
write_UDP (
    sock_t handle,                      /*  Socket handle                    */
    const void *buffer,                 /*  Buffer containing data           */
    size_t length,                      /*  Amount of data to write          */
    const struct sockaddr_in *sin       /*  Address to send to, or null      */
)

Synopsis

Writes data to a connected or unconnected UDP socket. To prepare a connected UDP socket you call connect UDP (). This makes a connection to a specific port on a specific host, and returns a socket handle. When you call this function with a null value for the address argument, it assumes you are using a connected UDP socket. To prepare an unconnected UDP socket, call create socket () with the string "udp" as argument. This returns a sock_t handle that you can use in this function. If you use an unconnected UDP socket you must provide an address structure containing a valid host and port. You can get this information from a read UDP () or through address end point (). If there is an error on the write this function returns SOCKET_ERROR. You can handle errors as fatal except for EAGAIN which indicates that the operation would cause a non-blocking socket to block. Treat EWOULDBLOCK as EAGAIN.

Source Code - (sflsock.c)

{
#if (defined (DOES_SOCKETS))
    int
        sin_length,                     /*  Length of address                */
        flags = 0,                      /*  Flags for call                   */
        rc;                             /*  Return code from call            */

    ASSERT (buffer);
    ASSERT (sin);
    sin_length = (int) sizeof (*sin);
    if (sin)
        /*  Write to unconnected UDP socket; we provide the address of       */
        /*  the receiving party in the sin argument.                         */
        rc = sendto ((SOCKET) handle, buffer, length, flags,
                    (struct sockaddr *) sin, sin_length);
    else
        /*  Write to a connected UDP socket; we don't need to supply         */
        /*  the address, since we already know it.                           */
        rc = send   ((SOCKET) handle, buffer, length, flags);

#   if (defined (__WINDOWS__))
    return (win_error (rc));
#   else
    return (rc);
#   endif
#else
    return ((int) SOCKET_ERROR);        /*  Sockets not supported            */
#endif
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation