Links Powered by MicMac
Cocoa-C-Porting
Fink's translation team
Mac OSX, Fink and Unix
Client/Server Architecture
PowerPC Architecture - UML
System programming
Merise
Pierre-Loïc and Pascaline's wedding

Functions Reference

Last modified: 22/04/2004 05:21:40 CEST
Author: Michèle Garoche contact

Contents - Overview - Diagrams - Client documentation - Server documentation - Functions documentation - Headers documentation - Client source code - Server source code - Functions source code - Headers source code -

wrapsock.c File Reference

Functions module. More...

Go to the source code of this file.

Includes

"wrapsock.h"

Functions

static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
Static function to handle errors.

static ssize_t mg_read (int fd, char *ptr)
Static function to catch errors while reading a stream.

void cliusage (char *progname)
Display an help message and quit, used in client when options are wrong.

void Inet_pton (int family, const char *strptr, void *addrptr)
Check if the address supplied by the user in client is valid, if not display an help message and quit.

void Connect (int fd, const struct sockaddr *sa, socklen_t salen)
Connect the client to the server's listening socket, if not display an help message and quit.

void str_cli (FILE *fp, int sockfd)
Attempt to write the client's request to the socket.

void servusage (char *progname)
Display an help message and quit, used in server when options are wrong.

void Bind (int fd, const struct sockaddr *sa, socklen_t salen)
Bind the name defined in the address structure to the socket, used in server.

void Listen (int fd, int backlog)
Listen for connection on the socket, used in server.

Sigfunc * Signal (int signo, Sigfunc *func)
Signal function to catch a SIGCHLD.

pid_t Fork (void)
Fork a child, if it fails display an error message and quit.

void Close (int fd)
Close the socket, if it fails display an error message and quit.

void str_serv1 (int sockfd)
Writes the result of request to the socket, for all types of requests.

void str_serv2 (int sockfd)
Writes the result of request to the socket, for numeric requests.

void str_serv3 (int sockfd)
Writes the result of request to the socket, for word requests.

int Socket (int family, int type, int protocol)
Create a socket.

char * Fgets (char *ptr, int n, FILE *stream)
Wrapper for fgets

ssize_t mg_readline (int fd, void *vptr, size_t maxlen)
Read a string character after character from a stream.

ssize_t Readline (int fd, void *ptr, size_t maxlen)
Wrapper for mg_readline.

void Fputs (const char *ptr, FILE *stream)
Wrapper for fputs.

ssize_t writen (int fd, const void *vptr, size_t n)
Write a string character after character to a stream.

void Writen (int fd, void *ptr, size_t nbytes)
Wrapper for writen.

int Select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Wait for read/write descriptors ready.

void Shutdown (int fd, int how)
Initiate a normal termination sequence.

void sig_chld (int signo)action to take when child terminates.

Sigfunc * mg_signal (int signo, Sigfunc *func)
Handle signals.

void err_sys (const char *fmt,...)
Handle errors generated by the system.

void err_quit (const char *fmt,...)
Handle errors not generated by the system.

Variables

int daemon_proc
in case launched at startup (not tested)


Detailed Description

Functions for tcpcli, tcpserv.

Definition in file wrapsock.c.


Function Documentation

static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
Static function to handle errors.

Parameters:
errnoflag => error type (1: system, 0: others).
level => log error.
fmt => string error passed to the function.
ap => vector list.

Definition at line 31 of file wrapsock.c.

Referenced by: err_quit(), and err_sys().

static ssize_t mg_read (int fd, char *ptr)
Static function to catch errors while reading a stream.

Parameters:
fd => file descriptor.
ptr => line to read.
Returns:
-1 if there is nothing to read, 0 if end of stream, 1 otherwise.

Definition at line 81 of file wrapsock.c.

Referenced by mg_readline().

void cliusage (char *progname)
Display an help message and quit, used in client when options are wrong.

Parameters:
progname => the program's name.

Definition at line 118 of file wrapsock.c.

References: err_quit().

Referenced by: lines 81, 109, 123, 137and 148 of file tcpcli.c.

void Inet_pton (int family, const char *strptr, void *addrptr)
Check if the address supplied by the user in client is valid, if not display an help message and quit.

Parameters:
family => the address family.
strptr => the address in string format.
addrptr => the address in network byte order.

Definition at line 143 of file wrapsock.c.

References: err_quit(), and err_sys().

Referenced by: line 176 of file tcpcli.c.

void Connect (int fd, const struct sockaddr *sa, socklen_t salen)
Connect the client to the server's listening socket, if not display an help message and quit.

Parameters:
fd => the socket's file descriptor.
sa => the address in address structure.
salen => the length of the address in address structure.

Definition at line 166 of file wrapsock.c.

References: err_sys().

Referenced by: line 180 of file tcpcli.c.

void str_cli (FILE *fp, int sockfd)
Attempt to write the client's request to the socket.

Parameters:
fp => the io to use.
sockfd => the socket to write to.
Bug:
The server refuses to bind thereafter till it receives ETIMEOUT.

Definition at line 179 of file wrapsock.c.

References: err_quit(), Fgets(), Fputs(), Readline(), Select(), Shutdown(), and Writen().

Referenced by: line 184 of file tcpcli.c.

void servusage (char *progname)
Display an help message and quit, used in server when options are wrong.

Parameters:
progname => the program's name.

Definition at line 263 of file wrapsock.c.

References: err_quit().

Referenced by: lines 99, 127, and 139 of file tcpserv.c.

void Bind (int fd, const struct sockaddr *sa, socklen_t salen)
Bind the name defined in the address structure to the socket, used in server.

Parameters:
fd => socket's file descriptor.
sa => name in the address structure.
salen => length of the name.

Definition at line 287 of file wrapsock.c.

References: err_sys().

Referenced by: line 167 of file tcpserv.c.

void Listen (int fd, int backlog)
Listen for connection on the socket, used in server.

Parameters:
fd => socket's file descriptor.
backlog => maximum length of pending connections queue.

Definition at line 301 of file wrapsock.c.

References: err_sys().

Referenced by: line 171 of file tcpserv.c.

Sigfunc * Signal (int signo, Sigfunc *func)
Signal function to catch a SIGCHLD.

Parameters:
signo => signal number.
func => callback to signal function.
Returns:
Sigfunc => the function to call to handle the signal.

Definition at line 315 of file wrapsock.c.

References: err_sys(), mg_signal().

Referenced by: line 175 of file tcpserv.c.

pid_t Fork (void)
Fork a child, if it fails display an error message and quit.

Returns:
the process identifier of the child process

Definition at line 332 of file wrapsock.c.

References: err_sys().

Referenced by: line198 of file tcpserv.c.

void Close (int fd)
Close the socket, if it fails display an error message and quit.

Parameters:
fd => the socket's file descriptor.

Definition at line 349 of file wrapsock.c.

References: err_sys().

Referenced by: lines 203, and 230 of file tcpserv.c.

void str_serv1 (int sockfd)
Writes the result of request to the socket, for all types of requests.

Parameters:
sockfd => the socket's file descriptor.

Definition at line 362 of file wrapsock.c.

References: Readline(), and Writen().

Referenced by: line 210 of file tcpserv.c.

void str_serv2 (int sockfd)
Writes the result of request to the socket, for numeric requests.

Parameters:
sockfd => the socket's file descriptor.

Definition at line 449 of file wrapsock.c.

References: Readline(), and Writen().

Referenced by: line 215 of file tcpserv.c.

void str_serv3 (int sockfd)
Writes the result of request to the socket, for word requests.

Parameters:
sockfd => the socket's file descriptor.

Definition at line 526 of file wrapsock.c.

References: Readline(), and Writen().

Referenced by: line 220 of file tcpserv.c.

int Socket (int family, int type, int protocol)
Create a socket.

Parameters:
family => the socket's family.
type => the socket's type.
protocol => the protocol used.
Returns:
the socket's file descriptor.

Definition at line 577 of file wrapsock.c.

References: err_sys().

Referenced by: line 156 of file tcpserv.c, and 166 of file tcpcli.c.

char * Fgets (char *ptr, int n, FILE *stream)
Wrapper for fgets

Parameters:
ptr => the buffer to write to .
n => the number of bytes to read.
stream => the stream to read from.
Returns:
the line.

Definition at line 597 of file wrapsock.c.

References: err_sys().

Referenced by: str_cli().

ssize_t mg_readline (int fd, void *vptr, size_t maxlen)
Read a string character after character from a stream.

Parameters:
fd => the socket's file descriptor.
vptr => the stream to read from.
maxlen => the number of bytes to read.
Returns:
the number of bytes read.

Definition at line 617 of file wrapsock.c.

References: mg_read().

Referenced by: Readline().

ssize_t Readline (int fd, void *ptr, size_t maxlen)
Wrapper for mg_readline.

Parameters:
fd => the file descriptor.
ptr => the buffer.
maxlen => the number of bytes to read.
Returns:
the number of bytes read.

Definition at line 663 of file wrapsock.c.

References: err_sys(), and mg_readline().

Referenced by: str_cli(), str_serv1(), str_serv2(), and str_serv3().

void Fputs (const char *ptr, FILE *stream)
Wrapper for fputs.

Parameters:
ptr => the line to write.
stream => the stream to write to.

Definition at line 681 of file wrapsock.c.

References: err_sys().

Referenced by: str_cli().

ssize_t writen (int fd, const void *vptr, size_t n)
Write a string character after character to a stream.

Parameters:
fd => the io to read from.
vptr => the stream to write to.
n => the number of bytes to write.
Returns:
the number of bytes written.

Definition at line 697 of file wrapsock.c.

Referenced by: Writen().

void Writen (int fd, void *ptr, size_t nbytes)
Wrapper for writen.

Parameters:
fd => the io to read from.
ptr => the stream to write to.
nbytes => the number of bytes to write.

Definition at line 733 of file wrapsock.c.

References: err_sys(), and writen().

Referenced by: str_cli(), str_serv1(), str_serv2(), and str_serv3().

int Select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Wait for read/write descriptors ready.

Parameters:
nfds => the number of descriptors to check.
readfds => the set of descriptor for read operations.
writefds => the set of descriptors for write operations.
exceptfds => the set of descriptors when there are pending exceptions.
timeout => the time limit to wait for ready descriptors.
Returns:
the number of descriptors ready.

Definition at line 751 of file wrapsock.c.

References: err_sys().

Referenced by: str_cli().

void Shutdown (int fd, int how)
Initiate a normal termination sequence.

Parameters:
fd => the socket's file descriptor.
how => the way to handle further sends and receives (0: receives disallowed, 1: sends disallowed, 2: both disallowed).

Definition at line 769 of file wrapsock.c.

References: err_sys().

Referenced by: str_cli().

void sig_chld (int signo)
action to take when child terminates.

Parameters:
signo => the signal number.

Definition at line 783 of file wrapsock.c.

Referenced by: line 175 of file tcpserv.c.

Sigfunc * mg_signal (int signo, Sigfunc *func)
Handle signals.

Parameters:
signo => the signal number.
func => the function to call.
Returns:
the function to call.

Definition at line 804 of file wrapsock.c.

Referenced by: Signal().

void err_sys (const char *fmt,...)
Handle errors generated by the system.

Parameters:
fmt => the string to pass.

Definition at line 835 of file wrapsock.c.

References: err_doit().

Referenced by: Bind(), Close(), Connect(), Fgets(), 193 of file tcpserv.c, Fork(), Fputs(), Inet_pton(), Listen(), Readline(), Select(), Shutdown(), Signal(), Socket(), and Writen().

void err_quit (const char *fmt,...)
Handle errors not generated by the system.

Parameters:
fmt => the string to pass.

Definition at line 854 of file wrapsock.c.

References: err_doit().

Referenced by: cliusage(), Inet_pton(), servusage(), and str_cli().


Variable Documentation

int daemon_proc
in case launched at startup (not tested)


Generated on Sat Mar 1 04:09:03 2003 for tcpcliserv by doxygen


Contents - Overview - Diagrams - Client documentation - Server documentation - Functions documentation - Headers documentation - Client source code - Server source code - Functions source code - Headers source code -

Powered by Apache/1.3.41 (Darwin) PHP/4.4.8 on Mac OS X bluefish distributed.net Cssed icon Conglomerate icon Valid HTML 4.0.1 Valid CSS
Local date (dd/mm/yyyy): 08/10/2008 13:21:22 CEST