Next: , Previous: , Up: Embedding API   [Contents][Index]

5.2.6 Networking and other low level functions

This chapter deals with the basic networking and file systems functions. It encapsulates systems calls in a portable manner. These functions should behave identically on Windows and Unices.

Function: char * svz_inet_ntoa (in_addr_t ip)

Convert ip, an address in network byte order, to its dotted decimal representation, returning a pointer to a statically allocated buffer. (You should copy the result.)

Function: int svz_inet_aton (char *str, struct sockaddr_in *addr)

Convert the Internet host address str from the standard numbers-and-dots notation into binary data and store it in the structure that addr points to. Return zero if the address is valid, nonzero otherwise. As a special case, if str is ‘*’ (asterisk), store INADDR_ANY in addr.

Function: int svz_closesocket (svz_t_socket sockfd)

Close the socket sock. Return 0 if successful, -1 otherwise.

Function: int svz_fd_cloexec (int fd)

Set the close-on-exec flag of the given file descriptor fd and return zero on success. Otherwise return non-zero.

Function: int svz_tcp_cork (svz_t_socket fd, int set)

Enable or disable the TCP_CORK socket option of the socket fd. This is useful for performance reasons when using sendfile with any prepending or trailing data not inside the file to transmit. Return zero on success, otherwise non-zero.

Function: int svz_tcp_nodelay (svz_t_socket fd, int set, int *old)

Enable or disable the TCP_NODELAY setting for the socket fd depending on the flag set, effectively enabling or disabling the Nagle algorithm. This means that packets are always sent as soon as possible and no unnecessary delays are introduced. If old is not NULL, save the old setting there. Return zero on success, otherwise non-zero.

Function: int svz_sendfile (int out_fd, int in_fd, off_t *offset, size_t count)

Transmit data between one file descriptor and another where in_fd is the source and out_fd the destination. The offset argument is a pointer to a variable holding the input file pointer position from which reading starts. On return, the offset variable will be set to the offset of the byte following the last byte that was read. count is the number of bytes to copy. Return the number of bytes actually read/written or -1 on errors.

Function: int svz_open (const char *file, int flags, mode_t mode)

Open the filename file and convert it into a file handle. The given flags specify the access mode and the mode argument the permissions if the O_CREAT flag is set.

Function: int svz_close (int fd)

Close the given file handle fd. Return -1 on errors.

Function: int svz_fstat (int fd, struct stat *buf)

Return information about the specified file associated with the file descriptor fd returned by svz_open. Store available information in the stat buffer buf.

Function: FILE * svz_fopen (const char *file, const char *mode)

Open the file whose name is the string pointed to by file and associate a stream with it.

Function: int svz_fclose (FILE *f)

Dissociate the named stream f from its underlying file.

Next: , Previous: , Up: Embedding API   [Contents][Index]