[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In this chapter the reader will find a short description of each function, global variable and macro the core library of Serveez provides. The API can either be used to implement a new server or coserver module for use with Serveez or for supporting network and server functionality within your own applications without caring about the details and system programming.
Most of the Serveez core library interface functionality should be
prefixed with svz_
. Small symbols will refer to functions and
variables in most cases and big letter symbols refer to macros.
3.1 Memory management | How memory is managed in Serveez | |
3.2 Data structures | Data structure helpers | |
3.3 Utility functions | Miscellaneous helper functions | |
3.4 Thread safety | Some thread-safety functionality | |
3.5 Networking and other low level functions | Network core implementations | |
3.6 Client connections | Client connection functions | |
3.7 Socket management | Socket management functions | |
3.8 Coserver functions | Coserver interface | |
3.9 Codec functions | Codec interface | |
3.10 Server type functions | Server type implementations | |
3.11 Server functions | Server object functions | |
3.12 Port configurations | Port configuration functions | |
3.13 Boot functions | Configuration and boot functions | |
3.14 Network interface functions | Network interface function implementation | |
3.15 Useful Windows functions | Windows port implementations |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The core library of Serveez is able to keep track of the memory an application or part of a program consumes and also controls itself in the same manner. When you are using this memory allocator interface you can determine and afterwards remove memory leaks. This is a very important feature if you consider servers being long term programs.
The three allocator function pointers for malloc()
, realloc()
and free()
make it possible to instruct Serveez to use different
kinds of memory, which might be necessary if you want the library to work
with shared memory arenas or any other underlying memory API.
Initial value: malloc
The svz_malloc_func variable is a function pointer for allocating
dynamic memory.
Initial value: realloc
This function pointer is called whenever the core library needs to
reallocate (resize) a memory block.
Initial value: free
In order to free a block of memory the core library calls this function
pointer.
Allocate size bytes of memory and return a pointer to this block.
Allocate size bytes of memory and return a pointer to this block. The memory is cleared (filled with zeros).
Change the size of a svz_malloc()
'ed block of memory. The size
argument is the new size of the block in bytes, The given variable
ptr must be a pointer previously returned by svz_malloc()
or
NULL
if you want to allocate a new block.
Free a block of svz_malloc()
'ed or svz_realloc()
'ed memory
block. If ptr is a NULL
pointer, no operation is performed.
Free the memory block pointed to by var and set it to NULL
afterwards. The argument var is passed to svz_free()
.
Duplicate the given string src if it is not NULL
and has
got a valid length (greater than zero). Return the pointer to the
copied character string.
Allocate a block of memory with the size size permanently. Memory allocated this way does not get into account of the libraries memory tracking.
Resize the memory block pointed to by ptr to size bytes. This routine also allocates memory permanently.
Duplicate the given character string src permanently.
Initial value: 0
The variable svz_allocated_bytes holds the overall number of bytes
allocated by the core library.
Initial value: 0
This variable holds the number of memory blocks reserved by the core
library.
Print a list of non-released memory blocks. This is for debugging only and should never occur in final software releases. The function goes through the heap hash and states each blocks address, size and caller.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Since most servers need to store information about its clients or want to keep track of data during runtime we implemented some of the most useful data pools. The actual aim was to provide higher level data structures which the programming language C does not support. Some of the included servers which come with Serveez make extensive use of them.
3.2.1 Array functions | A growable array implementation | |
3.2.2 Hashtable functions | Hashtable implementation | |
3.2.3 Sparsevector functions | Sparsevector implementation | |
3.2.4 Vectorlist functions | Vectorlist implementation |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The array data structure is a simple array implementation. Each array has got a size and capacity. The array indices range from zero to the arrays size minus one. You can put any kind of data into this array which fits into the size of a pointer. The array automatically grows if necessary.
Create a new array with the initial capacity capacity and return
a pointer to it. If capacity is zero it defaults to some value. The
destroy argument allows you to release dynamic allocated memory when
calling svz_array_clear()
and svz_array_destroy()
. If the
array contains data allocated by svz_malloc()
you need to set
destroy to svz_free()
. For structured data you can pass a
user defined routine which recurses into the structure. If the array
contains data which should not be released you must set destroy
to NULL
.
Delete all values within the array array and set its size to zero.
The array array itself keeps valid. Do not perform any operation
if array is NULL
. If you passed a destroy function to
svz_array_create()
the routine calls this function passing each
element of array to it.
Completely destroy the array array. The array handle is invalid afterwards. The routine runs the destroy callback for each element of the array.
This function destroys the given array array if it holds no
elements and returns NULL
in this case. Otherwise the
function returns the given array.
Return the array element at the position index of the array
array if the index is within the array range. Return NULL
if not.
Replace the array element at the position index of the array
array with the value value and return the previous value
at this index. Returns NULL
and does not perform any operation
if array is NULL
or the index is out of the array
range.
Append the value value at the end of the array array. Does
not perform any operation if array is NULL
.
Remove the array element at the position index of the array
array. Return its previous value or NULL
if the index
is out of the arrays range.
Return the given arrays array current capacity.
Return the given arrays array current size.
This routine inserts the given value value at the position index. The indices of all following values in the array array and the size of the array get automatically incremented. Return the values index or (-1) if the index is out of array bounds.
This function returns the index of the first occurrence of the value value in the array array. It returns (-1) if there is no such value stored within the array.
Returns how often the given value value is stored in the array array. Return zero if there is no such value.
This is the iteration macro for the array implementation of the core library. array specifies the array to iterate, value the pointer each element of the array gets assigned and i is the iteration variable.
This function works something like svz_array_dup()
but considers
the values within the array array to be zero-terminated character
strings and duplicates these via svz_strdup()
.
This function replicates the given array array. It returns
NULL
if there is nothing to do and an identical copy if the
array otherwise.
Create a NULL
terminated C array containing the values of the
given array. If the given array is NULL
then an empty
C array is returned. It is your responsibility to svz_free()
the
returned pointer.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A hashtable associates keys of arbitrary size and content with values. This data structure is also called associative array sometimes because you use keys in order to access values instead of numbers. You cannot store two values associated with the same key. The values can have any simple C types like integers or pointers.
Create a new hash table with an initial capacity size. Return a
non-zero pointer to the newly created hash. The size is calculated down
to a binary value. The destroy callback allows you to pass a
element destruction callback called within svz_hash_clear()
and
svz_hash_destroy()
for each value. If no such operation should be
performed the argument must be NULL
.
Destroy the existing hash table hash. Therefore we svz_free()
all keys within the hash, the hash table and the hash itself. The values
in the hash keep untouched if the element destruction callback passed to
svz_hash_create()
was NULL
, otherwise it is called for each
value. If hash is NULL
no operation is performed.
Clear the hash table of a given hash hash. Afterwards it does not
contains any key. In contradiction to svz_hash_destroy()
this
functions does not destroy the hash itself, but shrinks it to a minimal
size.
Delete an existing hash entry accessed via a given key key form the hash table hash. Return NULL if the key has not been found within the hash, otherwise the previous value.
This function adds a new element consisting of key and value to an existing hash hash. If the hash is 75% filled it gets rehashed (size will be doubled). When the key already exists then the value just gets replaced dropping and returning the old value. Note: This is sometimes the source of memory leaks.
Hash table lookup. Find a value for a given key in the hash table hash. Return NULL if the key has not been found within the hash table.
This function delivers all values within a hash table hash. It
returns NULL if there were no values in the hash. You MUST
svz_hash_xfree()
a non-NULL return value in order to prevent
memory leaks.
This function delivers all keys within a hash table hash. It
returns NULL if there were no keys in the hash. You MUST
svz_hash_xfree()
a non-NULL return value.
This routine delivers the number of keys in the hash table hash. If
the given hash is NULL
it returns zero.
This function returns the current capacity of a given hash table hash.
This function can be used to determine if some key points to the value argument in the hash table hash. Returns the appropriate key or NULL.
Returns a non-zero value if the given key
is stored within
the hash table hash
. Otherwise the function returns zero.
This function is useful when you cannot tell whether the return
value of svz_hash_get()
(== NULL
) indicates a real
value in the hash or a non-existing hash key.
Iterator macro for walking over the keys of a hash. Use like:
char **allkeys; int i; svz_hash_foreach_key (hash, allkeys, i) { printf ("%s => %p\n", allkeys[i], svz_hash_get (hash, allkeys[i])); } |
Be sure you pass real variables and no expressions to this macro !
Warning: Relatively slow implementation, builds up temporary array.
Do not break
or return
from inside the loop or your program
starts leaking memory ! Loop has to end normally.
Iterator macro for walking over the values of a hash. Use like:
type_t **values; int i; svz_hash_foreach_value (hash, values, i) { process_value (values[i]); } |
Be sure you pass real variables and no expressions to this macro !
Warning: Relatively slow implementation, builds up temporary array.
Do not break
or return
from inside the loop or your program
starts leaking memory ! Loop has to end normally.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A sparse vector is a kind of data array which grows and shrinks on demand. It unifies the advantages of chained lists (less memory usage than simple arrays) and arrays (faster access to specific elements). This implementation can handle gaps in between the array elements.
Construct an empty sparse vector without initial capacity. Return the newly created sparse vector.
Destroy the given sparse vector spvec completely. The argument cannot be used afterwards because it is invalid.
Appends the specified element value at the end of the sparse vector spvec.
Removes all of the elements from the sparse vector spvec. The
sparse vector will be as clean as created with svz_spvec_create()
then.
Returns non-zero if the sparse vector spvec contains the specified element value.
Returns the element at the specified position index in the sparse
vector spvec or NULL
if there is no such element.
Searches for the first occurrence of the given argument value. Return -1 if the value value could not be found in the sparse vector spvec.
Removes the element at the specified position index in the sparse vector spvec and returns its previous value.
Removes all of the elements whose index is between from (inclusive) and to (exclusive) from the sparse vector spvec. Returns the amount of actually deleted elements.
Replaces the element at the specified position index in the sparse vector spvec by the specified element value and return its previous value.
Delete the element at the given position index from the sparse
vector spvec but leave all following elements untouched
(unlike svz_spvec_delete()
). Return its previous value if there
is one otherwise return NULL
.
Returns the number of elements in the sparse vector spvec.
Returns the index of the last element of the sparse vector spvec plus one.
Inserts the specified element value at the given position index in the sparse vector spvec.
Delivers all values within the given sparse vector spvec in a
single linear chunk. You have to svz_free()
it after usage.
Rearranges the given sparse vector spvec. After that there are no more gaps within the sparse vector. The index - value relationship gets totally lost by this operation.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A vector list is an array of memory chunks with a fixed size. It holds copies of the values you added to the vector list. When deleting or inserting an element the indices of the following elements get either decremented or incremented. This data structure is especially useful if you actually want to forget about the pointers you put into it for it saves copies and not the pointers itself.
Create a new vector list without elements. Each element will have the given size size in bytes.
Destroy a given vector list vec. This pointer is invalid afterwards.
The routine svz_free()
s all elements.
Delete all elements of the given vector list vec. What you will have then is an empty vector list. Returns the previous length.
Add an element to the end of the given vector list vec. Return the position the element got. value is a pointer to a chunk of the vector lists chunk size.
Get an vector list element of the vector list vec at the given
position index. Return NULL
if the index is out of range.
Overwrite the element at index index in the vector list vec
with the given value value. Return NULL
if the index is out
of range or the pointer to the new element.
Delete the element of the vector vec at the position index. Return -1 if the given index is out of range otherwise the new length of the vector list.
Insert the given element value into the vector list vec at the position index. Return the new length of the vector list or -1 if the index is out of range.
Find the given value value in the vector list vec. Return -1 if there is no such element or the index of the element.
Return how often the vector list vec contains the element given in value.
Return the current length of the vector list vec.
Iteration macro for the vector list vector. Each of its values gets assigned to value. The iteration variable i runs from 0 to the size-1 of the vector list.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Within this section you will find some miscellaneous functionality and left overs of the C API.
Print a message to the log system. level specifies the prefix.
Set the file stream file to the log file all messages are printed
to. Could also be stdout
or stderr
.
Initial value: 0
This variable contains the the runtime detected Win32 version. Its value
is setup in svz_version()
and can be Win32s
for Windows 3.x,
Win95
for Windows 95, Win98
for Windows 98, WinNT3x
for Windows NT 3.x, WinNT4x
for Windows NT 4.x, Win2k
for
Windows 2000, WinXP
for Windows XP and WinME
for Windows ME.
Please note: This variable is only available on Windows version of this API.
Initial value: 0
This variable contains the last system or network error occurred if
it was detected and printed. Needed for the "Resource unavailable" error
condition.
Convert the byte array pointed to by p to a signed 16 bit integer.
Convert the byte array pointed to by p to a signed 32 bit integer. This is needed on aligned architectures where a plain type cast ends up in a fatal bus error.
Convert the byte array pointed to by p to a signed 64 bit integer.
Convert the byte array pointed to by p to an unsigned 16 bit integer.
Convert the byte array pointed to by p to an unsigned 32 bit integer.
Convert the byte array pointed to by p to an unsigned 64 bit integer.
Converts the integer value n into a pointer platform independently.
Both of the SVZ_NUM2PTR()
and SVZ_PTR2NUM()
macros rely on
the (unsigned long)
having the same size as (void *)
.
Convert the pointer p into a integer value platform independently.
Dump a buffer with the length len to the file stream out. You can specify a description in action. The hexadecimal text representation of the given buffer will be either cut at len or max. from is a numerical identifier of the buffers creator.
Converts an unsigned integer to its decimal string representation returning a pointer to an internal buffer, so copy the result.
Converts a given string str in decimal format to an unsigned integer. Stops conversion on any invalid characters.
Returns the current working directory. The returned pointer needs to be
svz_free()
'ed after usage.
This is the system dependent case insensitive string compare. It compares the strings str1 and str2 and returns zero if both strings are equal.
The svz_strncasecmp()
function compares the two strings str1
and str2, ignoring the case of the characters. It returns an
integer less than, equal to, or greater than zero if str1 is
found, respectively, to be less than, to match, or be greater than
str2. It only compares the first n characters of str1.
This routine checks for the current and maximum limit of open files of the current process. The function heavily depends on the underlying platform. It tries to set the limit to the given max_sockets amount.
Transform the given binary data t (UTC time) to an ASCII time text representation without any trailing characters.
Create some kind of uptime string. It tells how long the core library has been running.
Convert the given string str to lower case text representation.
This routine is for detecting the operating system version of Win32
and all Unices at runtime. You should call it at least once at startup.
It saves its result in the variable svz_os_version
and prints an
appropriate message.
This is the hstrerror()
wrapper function, depending on the
configuration file `config.h'.
Routine which forms a valid error message under Win32. It might either
use the GetLastError()
or WSAGetLastError()
in order to
get a valid error code.
Implementation of the snprintf()
if it is not defined. It uses
the vsnprintf()
function therefore which will fall back to
vsprintf()
if vsnprintf()
does not exist.
Implementation of asprintf()
. The function uses
svz_vasprintf()
. It can be used to format a character
string without knowing the actual length of it. The routine
dynamically allocates buffer space via svz_malloc()
and
returns the final length of the string. The calling function is
responsible to run svz_free()
on str.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following macros and functions can be used to implement certain thread safety functionality inside applications using the core library (including Serveez itself). The user must explicitly enable this functionality when configure'ing the Serveez package. Otherwise the macros default to empty statements.
Defines a mutex object globally.
Declares a mutex object externally. This is useful when the mutex object is defined in another file.
Creates and initializes the given mutex object. The mutex is
in an unlocked state. The macro must be called before using
svz_mutex_lock()
or svz_mutex_unlock()
. The user
must call svz_mutex_destroy()
for each mutex created by this
function.
Destroys the given mutex object which has been created by
svz_mutex_create()
.
Locks a mutex object and sets the current thread into an idle state if the mutex object has been currently locked by another thread.
Releases the given mutex object and thereby possibly resumes
a waiting thread calling svz_mutex_lock()
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following chapter deals with the basic networking and file systems functions. It encapsulates systems calls in a portable manner. These functions should behave identical on Windows and Unices.
Converts the given ip address ip to the dotted decimal representation. The string is a statically allocated buffer, please copy the result. The given ip address MUST be in network byte order.
Converts the Internet host address str from the standard
numbers-and-dots notation into binary data and stores it in the
structure that addr points to. svz_inet_aton()
returns
zero if the address is valid, nonzero if not.
This function handles an ip address of "*" special and sets
INADDR_ANY
for it.
Connect the given socket descriptor sockfd to the host host at the network port port. Return non-zero on errors.
Create a new non-blocking socket which does not get inherited on
exec()
. The protocol is specified by proto. Return the
socket descriptor or -1 on errors.
This function creates an unnamed pair of connected sockets with the specified protocol proto. The descriptors used in referencing the new sockets are returned in desc[0] and desc[1]. The two sockets are indistinguishable. Also make both of them non-blocking and non-inheritable. Returns -1 on failure, otherwise zero.
Saves the socket type (like SOCK_STREAM
, SOCK_DGRAM
, etc.)
of the socket fd in the buffer pointed to by type. Returns
zero on success.
Set the close-on-exec flag of the given file descriptor fd and return zero on success. Otherwise return non-zero.
Set the given file descriptor to nonblocking I/O. This heavily differs in Win32 and Unix. The given file descriptor fd must be a socket descriptor under Win32, otherwise the function fails. Return zero on success, otherwise non-zero.
Set the given file descriptor to blocking I/O. This routine is the
counter part to svz_fd_nonblock()
.
Enable or disable the TCP_CORK
socket option of the given socket
descriptor fd. This is useful for performance reasons when using
sendfile()
with any prepending or trailing data not inside the
file to transmit. The function return zero on success, otherwise non-zero.
Enable or disable the TCP_NODELAY
setting for the given socket
descriptor fd depending on the flag set. In fact its turns
the Nagle algorithm on or off. This means that packets are always sent
as soon as possible and no unnecessary delays are introduced. The
function saves the old setting if old is not NULL
. Returns
zero on success, otherwise non-zero.
This function transmits 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. When this routine returns, 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 between file descriptors. Returns the number of bytes actually read/written or -1 on errors.
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.
Close the given file handle fd. Return -1 on errors.
Return information about the specified file associated with the file
descriptor fd returned by svz_open()
. Stores available
information in the stat buffer buf.
Open the file whose name is the string pointed to by file and associates a stream with it.
Dissociates the named stream f from its underlying file.
Constructs a fully qualified file name form path and file.
If path is omitted (NULL
) the function returns file
only. If file is NULL
a null pointer is returned.
Please remember to svz_free()
the returned pointer.
Checks for the existence of the given file system node file and return zero on success. Otherwise the function returns non-zero.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Serveez tries to handle all kinds of Internet protocols like TCP (connection
oriented), UDP, ICMP and RAW (packet oriented) and communication across
named pipes (also connection oriented) in the same way. Therefore it uses
a structure called svz_socket_t
which is the abstraction of any kind
of communication endpoint (can be client or server or both together).
3.6.1 TCP sockets | TCP socket functions | |
3.6.2 Pipe connections | Named and anonymous pipe functions | |
3.6.3 UDP sockets | UDP socket functions | |
3.6.4 ICMP sockets | ICMP socket functions | |
3.6.5 Raw sockets | Raw socket functions | |
3.6.6 Passthrough connections | Passthrough connections to child processes |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
TCP sockets provide a reliable, stream oriented, full duplex connection between two sockets on top of the Internet Protocol (IP). TCP guarantees that the data arrives in order and retransmits lost packets. It generates and checks a per packet checksum to catch transmission errors. TCP does not preserve record boundaries.
Create a TCP connection to host host and set the socket descriptor in structure sock to the resulting socket. Return a zero value on errors.
The default routine for connecting a socket sock. When we get
select()
ed or poll()
ed via the WRITE_SET we simply
check for network errors,
Default function for reading from the socket sock. This function
only reads all data from the socket and calls the check_request()
function for the socket, if set. Returns -1 if the socket has died,
returns zero otherwise.
Default function for writing to the socket sock. Simply flushes the output buffer to the network. Write as much as possible into the socket sock. Writing is performed non-blocking, so only as much as fits into the network buffer will be written on each call.
This function is the default read_socket_oob()
callback for
TCP sockets. It stores the received out-of-band data (a single byte
only) in sock->oob
and runs the check_request_oob()
callback
if it is set properly. Returns -1 on failure and zero otherwise. The
function does not do anything if the underlying operating system does not
support urgent data and simply returns -1.
If the underlying operating system supports urgent data (out-of-band) in
TCP streams this function tries to send the byte in sock->oob
through the socket structure sock as out-of-band data. The function
returns zero on success and -1 otherwise (also if urgent data is not
supported).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The pipe implementations supports both named and anonymous pipes. Pipe servers are implemented as listeners on a file system FIFO on Unices or "Named Pipes" on Windows (can be shared over a Windows network).
A FIFO special file is similar to a pipe, except that it is created in a different way. Instead of being an anonymous communications channel, a FIFO special file is entered into the file system.
Once you have created a FIFO special file in this way, any process can open it for reading or writing, in the same way as an ordinary file. However, it has to be open at both ends simultaneously before you can proceed to do any input or output operations on it.
Startup the pipe interface of the core API of serveez. Returns zero on
success. Gets called from svz_boot()
once. Do not use.
Cleanup the pipe interface of the core API of serveez. Returns zero on
success. Gets called from svz_halt()
once. Do not use.
Return a newly allocated and setup to some defaults pipe structure.
Destroy the given pipe structure pipe.
This function is for checking if a given socket structure contains a valid pipe socket (checking both pipes). Return non-zero on errors.
The svz_pipe_read_socket()
function reads as much data as
available on a readable pipe descriptor or handle on Win32. Return
a non-zero value on errors.
This svz_pipe_write_socket()
function writes as much data as
possible into a writable pipe descriptor. It returns a non-zero value
on errors.
This function is the default disconnection routine for pipe socket structures. Return non-zero on errors.
Create a socket structure containing both the pipe descriptors
recv_fd and send_fd. Return NULL
on errors.
Create a (non blocking) pair of pipes. This differs in Win32 and Unices. Return a non-zero value on errors.
This routine creates a pipe connection socket structure to a pair of
named pipes. Return NULL
on errors.
Prepare the server socket structure sock for listening on the receiving pipe of recv. Open the reading end of such a connection. Return either zero or non-zero on errors.
Check the consistency of the "user" - "user id" pair in the given pipe structure pipe. Return zero if it is ok.
Check the consistency of the "group" - "group id" pair in the structure pipe. Return zero if it is valid.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The UDP sockets implement a connectionless, unreliable datagram packet service. Packets may be reordered or duplicated before they arrive. UDP generates and checks checksums to catch transmission errors.
This routine is the default reader for UDP sockets. Whenever the socket
descriptor is select()
'ed for reading it is called by default and
reads as much data as possible (whole packets only) and saves the sender
into the sock->remote_addr
field. The packet load is written into
sock->recv_buffer
.
This routine is the default reader for UDP server sockets. It allocates
necessary buffers (that's why it's called lazy) and reverts to the default
svz_udp_read_socket()
.
The svz_udp_write_socket()
callback should be called whenever
the UDP socket descriptor is ready for sending. It sends a single packet
within the sock->send_buffer
to the destination address specified
by sock->remote_addr
and sock->remote_port
.
This is the default check_request()
routine for UDP servers.
Whenever new data arrived at an UDP server socket we call this function to
process the packet data. Any given handle_request()
callback MUST
return zero if it successfully processed the data and non-zero if it
could not.
Create a UDP connection to host and set the socket descriptor in
structure sock to the resulting socket. Return a NULL
value
on errors. This function can be used for port bouncing. If you assign the
handle_request
callback to something server specific and the
cfg field to the server's configuration to the returned socket
structure this socket is able to handle a dedicated UDP connection to
some other UDP server.
Write the given buf into the send queue of the UDP socket. If the length argument supersedes the maximum length for UDP messages it is split into smaller packets.
Print a formatted string on the UDP socket sock. fmt is
the printf()-style format string, which describes how to format the
optional arguments. See the printf(3) manual page for details. The
destination address and port is saved for sending. This you might
specify them in sock->remote_addr
and sock->remote_port
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The ICMP socket implementation is currently used in the tunnel server which comes with the Serveez package. It implements a user protocol receiving and sending ICMP packets by opening a raw socket with the protocol IPPROTO_ICMP.
The types of ICMP packets passed to the socket can be filtered using the ICMP_FILTER socket option (or by software as done here). ICMP packets are always processed by the kernel too, even when passed to a user socket.
Load the `ICMP.DLL' library into process address space and get all necessary function pointers.
Shutdown the ping service.
Default reader for ICMP sockets. The sender is stored within
sock->remote_addr
and sock->remote_port
afterwards.
Default reader for ICMP server sockets. Allocates necessary buffers and
reverts to svz_icmp_read_socket()
.
The default ICMP write callback is called whenever the socket
descriptor has been select()
'ed or poll()
'ed to be ready for
sending.
Default check_request()
callback for ICMP sockets.
This function creates an ICMP socket for receiving and sending.
Return NULL
on errors, otherwise an enqueued socket structure.
If you are calling this function we will send an empty ICMP packet signaling that this connection is going down soon.
Send a given buffer buf with length length via this ICMP socket. If the length argument supersedes the maximum ICMP message size the buffer is split into smaller packets.
Put a formatted string to the icmp socket sock. Packet length and
destination address are additionally saved to the send buffer. The
destination is taken from sock->remote_addr
. Furthermore a valid
icmp header is stored in front of the actual packet data.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A raw socket receives or sends the raw datagram not including link level headers. It is currently used by the ICMP socket implementation of the core library. The IPv4 layer generates an IP header when sending a packet unless the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header. For receiving the IP header is always included in the packet.
Only processes with an effective userid of 0 (Administrator or root) or the CAP_NET_RAW capability are allowed to open raw sockets. All packets or errors matching the protocol number specified for the raw socket are passed to this socket. A protocol of IPPROTO_RAW implies enabled IP_HDRINCL and receives all IP protocols. Sending is not allowed.
Get IP header from plain data.
Put IP header to plain data. This is currently not in use but can be used when creating raw sockets with setsockopt (SOL_IP, IP_HDRINCL).
Recalculate any IP checksum.
Checking the IP header only. Return the length of the header if it is valid, otherwise -1.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The function subset described in the following section allows the user to
passthrough client connections to the standard input (stdin) and standard
output (stdout) handles of external programs. Some of the routines deal
with the management of program environments. Basically there are two
methods how to passthrough a duplex connection: the Unix'ish fork()
and exec()
method and the shuffle method where the main process
keeps control over the communication on the original duplex connection and
passes this data through two pairs of pipes or yet another socket connection
to the child process. All of the three method are implemented calling them
SVZ_PROCESS_FORK
, SVZ_PROCESS_SHUFFLE_PIPE
and
SVZ_PROCESS_SHUFFLE_SOCK
.
This routine starts a new program specified by bin passing the
socket or pipe descriptor(s) in the socket structure sock to its
stdin and stdout.
The bin argument has to contain a fully qualified executable file
name and the dir argument contains the working directory of the
new process. The directory is not changed when this argument is
NULL
.
The program arguments and the environment of the new process can be
passed in argv and envp. Please note that argv[0]
has
to be set to the program's name, otherwise it defaults to bin if
it contains NULL
.
The flag argument specifies the method used to passthrough the
connection. It can be either SVZ_PROCESS_FORK
(in order to pass
the pipe descriptors or the socket descriptor directly through
fork()
and exec()
) or SVZ_PROCESS_SHUFFLE_PIPE
/
SVZ_PROCESS_SHUFFLE_SOCK
(in order to pass the socket transactions
via a pair of pipes or sockets).
You can pass the user and group identifications in the format
`user[.group]' (group is optional), as SVZ_PROCESS_NONE
or SVZ_PROCESS_OWNER
in the user argument. This specifies the
permissions of the new child process. If SVZ_PROCESS_OWNER
is
passed the permissions are set to the executable file bin owner;
SVZ_PROCESS_NONE
does not change user or group.
The function returns -1 on failure and otherwise the new process's pid.
Disconnection routine for the socket connection sock which is connected with a process's stdin/stdout via the referring passthrough socket structure which gets also scheduled for shutdown if possible.
Disconnection routine for the passthrough socket structure sock connected with a process's stdin/stdout. Schedules the referring socket connection for shutdown if necessary and possible.
Check request routine for the original passthrough connection sock. Sets the send buffer fill counter of the referring socket structure which is the passthrough connection in order to schedule it for sending.
Idle function for the passthrough shuffle connection sock. The routine checks whether the spawned child process is still valid. If not it schedules the connection for shutdown. The routine schedules itself once a second.
This is the shuffle pipe writer (reading end of a process's stdin). It writes as much data as possible from the send buffer which is the receive buffer of the referring socket structure. Returns non-zero on errors.
This is the shuffle pipe reader (writing end of a process's stdout). It reads as much data as possible into its receive buffer which is the send buffer of the connection this passthrough pipe socket structure stems from.
This is the shuffle socket pair writer which is directly connected with the reading end of the child process. It writes as much data as possible from its send buffer which is the receive buffer of the original passthrough connection.
This is the shuffle socket pair reader which is directly connected with the writing end of the child process. It reads as much data as possible into its receive buffer which is the send buffer of the original passthrough connection.
Spawns a new child process. The given proc argument contains all information necessary to set a working directory, assign a new user defined stdin and stdout of the new process, to set up a process environment, pass a command line to the new process and to specify a user and group identification the child process should have. The routine returns -1 on failure, otherwise the new child program's process id.
Please note:
On M$-Windows platforms it is not possible to pass a socket connection
to a child process's stdin/stdout. That is why this function creates an
inheritable version of the socket and puts the socket handle number
into the environment variables SEND_HANDLE
and RECV_HANDLE
.
A spawned child process can use these handles as if these were created
by itself. After calling WSAStartup()
the child process can
send()
and recv()
as usual.
Creates two pairs of pipes in order to passthrough the transactions of
the a socket structure. The function create a new socket structure and
sets it up for handling the transactions automatically. The given
argument proc contains the information inherited from
svz_sock_process()
. The function returns -1 on failure and the
new child's process id otherwise.
Fork the current process and execute a new child program. The given
argument proc contains the information inherited from
svz_sock_process()
. The routine passes the socket or pipe
descriptors of the original passthrough socket structure to stdin and
stdout of the child. The caller is responsible for shutting down the
original socket structure. Returns -1 on errors and the child's
process id on success.
Check if the given file is an executable (script or binary program). If it is script the routine returns an application able to execute the script in app. Returns zero on success, non-zero otherwise.
Splits the given character string str in the format
`user[.group]' into a user name and a group name and stores
pointers to it in user and group. If the group has been
omitted in the format string then group is NULL
afterwards. The function returns zero on success, or non-zero if the
given arguments have been invalid.
Try setting the user and group for the current process specified by the
given executable file file and the user argument. If user
equals SVZ_PROCESS_NONE
no user or group is set. When you pass
SVZ_PROCESS_OWNER
in the user argument the file's owner
will be set. Otherwise user specifies the user and group
identification in the format `user[.group]'. If you omit the group
information the routine uses the primary group of the user. Returns zero
on success, non-zero otherwise.
Create a fresh environment block. The returned pointer can be used to pass
it to svz_envblock_default()
and svz_envblock_add()
. Its
size is initially set to zero.
Fill the given environment block env with the current process's environment variables. If the environment env contained any information before these will be overridden.
Insert a new environment variable into the given environment block env. The format argument is a printf()-style format string describing how to format the optional arguments. You specify environment variables in the `VAR=VALUE' format.
This function releases all environment variables currently stored in the
given environment block env. The block will be as clean as returned
by svz_envblock_create()
afterwards.
Destroys the given environment block env completely. The env argument is invalid afterwards and should therefore not be referenced then.
Unfortunately the layout of environment blocks in Unices and Windows
differ. On Unices you have a NULL terminated array of character strings
and on Windows systems you have a simple character string containing
the environment variables in the format VAR=VALUE each separated by a
zero byte. The end of the list is indicated by a further zero byte.
The following routine converts the given environment block env
into something which can be passed to exeve()
(Unix) or
CreateProcess()
(Windows). The routine additionally sorts the
environment block on Windows systems since it is using sorted
environments.
This macro must be called once after svz_boot()
for setting up the
svz_environ
variable. It simply passes the environ
variable
of the calling application to the underlying Serveez core API. This is
necessary to make the svz_envblock_default()
function working
correctly.
Initial value: NULL
This variable is meant to hold the environ
variable of the
application using the Serveez core API. It must be setup via the macro
svz_envblock_setup()
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The function subset described in the following section deals with the
creation, destruction and other simple operations on socket structures
called svz_socket_t
. See for the details at the description of each
function which kind of socket it can handle and what they are for.
Initial value: 0
Count the number of currently connected sockets.
Check if a given socket is still valid. Return non-zero if it is not.
Allocate a structure of type svz_socket_t
and initialize its data
fields. Assign some of the default callbacks for TCP connections.
Free the socket structure sock. Return a non-zero value on error.
Create a socket structure from the file descriptor fd. Set the
socket descriptor to non-blocking I/O. Return NULL
on errors.
Disconnect the socket sock from the network and calls the disconnect function for the socket if set. Return a non-zero value on errors.
Write len bytes from the memory location pointed to by buf to the output buffer of the socket sock. Also try to flush the buffer to the socket of sock if possible. Return a non-zero value on error, which normally means a buffer overflow.
Print a formatted string on the socket sock. fmt is the printf()-style format string, which describes how to format the optional arguments. See the printf(3) manual page for details.
Resize the send and receive buffers for the socket sock. send_buf_size is the new size for the send buffer, recv_buf_size for the receive buffer. Note that data may be lost when the buffers shrink. For a new buffer size of 0 the buffer is freed and the pointer set to NULL.
Get local and remote addresses and ports of socket sock and save them into the socket structure.
This function returns the local network address and port for the given client socket structure sock. It returns non-zero if there no connection established.
Get and clear the pending socket error of a given socket. Print the result to the log file.
Calculate unique socket structure id and assign a version for a given sock. The version is for validating socket structures. It is currently used in the coserver callbacks.
This routine gets called whenever data is read from a client socket accepted by any connection oriented protocol layer (TCP or PIPE). We try to detect the data streams protocol here.
This function simply checks for the kind of packet delimiter within the
given socket structure and and assigns one of the default
check_request()
routines (one or more byte delimiters or a fixed
size). Afterwards this routine will never ever be called again because
the callback gets overwritten here.
Default idle function. This routine simply checks for "dead" (non-receiving) sockets (connection oriented protocols only) and rejects them by return a non-zero value.
This routine can be called if flood protection is wished for socket readers. Return non-zero if the socket should be kicked because of flood.
Shorten the receive buffer of sock by len bytes.
Reduce the send buffer of sock by len bytes.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following section describes the internal coserver interface of serveez. Coservers are helper processes meant to perform blocking tasks. This is going to be necessary because serveez itself is single threaded. Each coserver is connected via a pair of pipes to the main thread of serveez communicating over a simple text line protocol. Each request/response is separated by a newline character.
If the user wants to use these processes you need to start the coserver
interface by calling svz_coserver_init()
once before entering the
main server loop and shut it down afterwards by calling
svz_coserver_finalize()
.
This static array contains the coserver structure for each type of internal coserver the core library provides.
Initial value: NULL
Internal coserver instances.
Call this routine whenever there is time, e.g. within the timeout of
the select()
statement. Indeed I built it in the
svz_periodic_tasks()
statement. Under Wind32 the routine checks
if there was any response from an active coserver. Moreover it keeps
the coserver threads/processes alive. If one of the coservers dies due
to buffer overrun or might be overloaded this function starts a new one.
Global coserver initialization. Here you should start all the internal coservers you want to use later.
Global coserver finalization.
Destroy specific coservers with the type type. This works for Win32 and Unices. All instances of this coserver type will be stopped.
Create a single coserver with the given type type.
Invoke a request for one of the running internal coservers with type type. handle_result and arg specify what should happen if the coserver delivers a result.
This is a wrapper function for the reverse DNS lookup coserver.
This macro is considered to be the usual way to make a request to the
reverse DNS coserver. It calls svz_coserver_rdns_invoke()
therefore.
If the given ip has been resolved by the coserver to a valid computer
name the callback cb gets invoked with the additional arguments
passed to this macro.
Wrapper for the DNS coserver.
This macro is the usual way to make use of the internal DNS coserver. When the given computer name host has been resolved to a valid ip address the function cb will be called with the additional arguments arg0 and arg1.
Wrapper for the ident coserver.
This macro uses the internal ident coserver in order to identify the connection of the given socket structure sock. The function cb will be called when the coserver successfully delivers the identified user on the other end of the connection. Both the arguments arg0 and arg1 are passed to cb.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The codec interface of the serveez core API supplies routines for setting up socket structures to perform encoding or decoding of its receive or send buffers. It is a transparent layer of buffer transition. The interface itself tries to unify different types of codecs. In order to add a new codec the programmer needs to write some wrapper functions around the actual implementation to fulfil certain entry and exit semantics of this interface.
Prints the text representation of the list of known codecs registered
within the core library. This includes all encoder and decoder once ran
through svz_codec_register()
.
Find an appropriate codec for the given description and type
which can be either SVZ_CODEC_ENCODER
or SVZ_CODEC_DECODER
.
The function returns NULL
if there is no such codec registered.
This routine is called by svz_boot()
and registers the builtin
codecs.
This routine is called by svz_halt()
and destroys the list of
known codecs.
Print a text representation of a codec's current ratio in percent if possible.
Register the given codec codec. Does not register invalid or duplicate codecs. Returns zero on success, non-zero otherwise.
Removes the given codec codec from the list of known codecs. Returns zero if the codec could be successfully removed, non-zero otherwise.
Setup the given socket structure sock to decode or encode its
receive data via the codec codec. Therefore you must have setup
the check_request
method previously. The function returns zero
on success, non-zero otherwise.
This routine is the new check_request
callback for reading codecs.
It is applied in the above svz_codec_sock_receive_setup()
function.
Usually it gets called whenever there is data in the receive buffer. It
lets the current receive buffer be the input of the codec. The output
buffer of the codec gets the new receive buffer buffer of the socket
structure sock. The old check_request
callback of sock
gets called afterwards. When leaving this functions the receive buffer
gets restored again with the bytes snipped consumed by the codec itself.
Setup the socket structure sock for encoding or decoding its send
buffer via the given codec codec. Therefore you previously need to
assign the write_socket
member of sock properly. The function
returns zero on success, non-zero otherwise.
This is a codec socket structures sock new write_socket
callback which is called whenever there is data within the send buffer
available and sock is scheduled for writing. It uses the current
send buffer as input buffer for the codec. The output buffer of the codec
is used to invoke the write_socket
callback saved within
svz_codec_sock_send_setup()
. After this the send buffer is
restored again without the bytes consumed by the codec.
This callback is used as the disconnected_socket
callback of the
socket structure sock. It tries to release the resources of both
the receiving and sending codec of sock. The routine is called by
default if the codec socket structure sock gets disconnected for
some external reason.
This routine can be used to detect a codec on the receive buffer of the
given socket structure sock. It returns a valid codec or NULL
if no codec could be detected.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As already noted in the main serveez manual a server type is the
main specification of the abilities and configuration items of a server
which can be instantiated. It is represented by the C structure
svz_servertype_t
in serveez. It contains server specific members
like its name, different callbacks, a single default configuration and a
list of configuration items which determines what can be configured.
3.10.1 Macros for setting up a new server type | Setting up a server type | |
3.10.2 General server type functionality | Server type implementation | |
3.10.3 Dynamic server loading | Dynamic server type loading |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When specifying a server type you also need to define configuration items for it. These items refer to addresses in the example configuration of the server type. The following macros can be used to determine these items.
Register a simple integer. C-type: int
. The given name
specifies the symbolic name of the integer and item the integer
itself (not its address). The defaultable argument can be either
SVZ_ITEM_DEFAULTABLE
or SVZ_ITEM_NOTDEFAULTABLE
.
Register a boolean value. C-type: int
.
Register an array of integers. C-type: svz_array_t *
.
Register a simple character string. C-type: char *
.
Register a string array. C-type: svz_array_t *
.
Register a hash table associating strings with strings only. C-type:
svz_hash_t *
.
Register a port configuration. C-type: svz_portcfg_t *
.
This macro indicates the end of the list of configuration items. It is the only mandatory item you need to specify in an example server type configuration.
Macro for defining the example configuration config (with the name description and its configuration items prototypes within a server type definition.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following set of functions are used to manage the list of known server types in the serveez core library. Serveez itself uses some of these functions to register its builtin server types.
Initial value: NULL
The list of registered servers. Feel free to add yours.
Add the server type server to the currently registered servers.
Delete the server type with the index index from the list of known server types and run its global finalizer if necessary. Moreover we remove and finalize each server instance of this server type.
Find a servertype definition by its short name. If dynamic is set
to non-zero an attempt is made to load a shared library that provides
that servertype. Returns NULL
if no server with the given variable
prefix name has been found.
Find a given server instances server server type. Return NULL
if there is no such server type (which should never occur since a server is
a child of an server type.
Run the global finalizers of each server type and delete all server types.
Debug helper function to traverse all currently known server types.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The core API of serveez is able to register server types dynamically at runtime. It uses the dynamic linker capabilities of the underlying operating system to load shared libraries (or DLLs on Win32). This has been successfully tested on Windows and GNU/Linux. Other systems are supported but yet untested. Please tell us if noticing any misbehaviour.
Initialize the shared library interface of the core library.
Finalize the shared library interface of the core library. Unload all libraries no matter if referenced or not.
Load an additional server definition from a shared library. The given descriptive name description must be part of the library's name.
Unload a server definition from a shared library. The given descriptive name description must be part of the library's name. Return the remaining reference count or -1 on errors.
Set the additional search paths for the serveez library. The given array of
strings gets svz_free()
d.
Create an array of strings containing each an additional search path.
The loadpath is hold in the environment variable `SERVEEZ_LOAD_PATH'
which can be set from outside the library or modified using
svz_dynload_path_set()
. The returned array needs to be destroyed
after usage.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A server in serveez is an instantiated (configured) server type. It is
merely a copy of a specific server type with a unique server name. It is
represented by the C structure svz_server_t
in the core library.
3.11.1 General functionality | General server instance implementations | |
3.11.2 Configuration | Server instance configuration | |
3.11.3 Bindings | Server instance bindings | |
3.11.4 Server core | Core functionality for servers | |
3.11.5 Server loop | Server loop implementation | |
3.11.6 Server sockets | Using and creating server sockets |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following section contains functions dealing with the list of known servers in the core library of serveez, also with the basics like creation and destruction of such servers.
Initial value: NULL
This is the list of actually instantiated servers. The hash table
associates the servers' names with the server instances.
Find a server instance by the given configuration structure cfg.
Return NULL
if there is no such configuration in any server
instance.
Returns a list of clients (socket structures) which are associated
with the given server instance server. If there is no such
socket NULL
is returned. The calling routine is responsible
to svz_array_destroy()
the returned array.
Add the server instance server to the list of instantiated
servers. Returns the previous value of that server if any or NULL
otherwise.
Get the server instance with the given instance name name.
Return NULL
if there is no such server yet.
Remove the server instance identified by the name name.
This function runs the server initilizer of the given server instance server and returns zero on success. Otherwise it emits an error message and returns non-zero.
This function runs the finalizer callback for the given server instance server, removes all bindings and frees all resources allocated by the server instance.
Create a new server instance of the server type stype with the instance name name.
Run all the server instances's notify routines. This should be regularly
called within the svz_periodic_tasks()
function.
Runs each server instance's reset callback. The callbacks are run when
a SIGHUP
signal has been detected by the internal signal handler
of the core library.
Run the initializers of all servers, return -1 if some server did not think it is a good idea to run.
Run the local finalizers for all server instances.
Completely destroy the given server instance server. This especially means to go through each item of the server instances configuration.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions provide an interface for configuring a server. They are used to create and modify the default configuration of a server type in order to create a server configuration.
This function configures a server instance by modifying its default
configuration by the configure callbacks. Therefore you need
to pass the type of server in server, the name of the
server instance and the (optional) modifier callback structure
configure. The arg argument is passed to each of the
callbacks (e.g. specifying a scheme cell). The function returns
either a valid server instance configuration or NULL
on
errors.
Add the configurable type described by type to the list of known configurable types.
Instantiate a configurable type. The type argument specifies the configurable type name, name the name of the type (in the domain of the configurable type) and instance the instance name of the type. Returns zero on success, otherwise -1.
Adds the configurable types of Serveez. This function is called
from svz_boot()
.
Removes the list of known configurable types and is called from
svz_halt()
.
This function is a debug helper for checking the layout of the configuration prototype prototype.
Release the configuration cfg of the given configuration
prototype prototype. If the configuration equals NULL
no operation is performed.
This functions is used to instantiate the configuration prototype prototype using the accessor callbacks accessor depending on the type of items in the prototype. The additional argument arg is passed to each of these callbacks. The name argument should be used to pass the instance name of the object which is going to be configured.
Create an array (svz_array_t
) of integers. The given integer
array intarray is a list of integers where its first element which
is intarray[0]
contains the actual length of the given array.
Destroy the given integer array intarray. This function is the
counter part of svz_config_intarray_create()
.
Make a plain copy of the given integer array intarray. If this
value is NULL
no operation is performed and the return value
is NULL
too.
Create an array of strings. The given list of strings strarray
must be NULL
terminated in order to indicate its end.
Destroy the given string array strarray.
Duplicate the given array of strings strarray. Return NULL
if strarray equals NULL
.
Create a hash table from the given array of strings strarray which
must be NULL
terminated in order to indicate the end of the list.
The array consists of pairs of strings where the first one specifies a
key and the following the associated string value. This function is
useful when creating default values for server type configurations.
This function is the counter part of svz_config_hash_create()
. It
destroys the given hash table strhash assuming it is a hash
associating strings with strings.
Duplicate the given hash table strhash assuming it is a hash
associating strings with strings. Return NULL
if strhash is
NULL
too.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following functionality represents the relationship between port configurations as described in Port configurations and server instances. When binding a server to a specific port configuration the core library creates listeners as needed by itself.
Bind the server instance server to the port configuration port if possible. Return non-zero on errors otherwise zero. It might occur that a single server is bound to more than one network port if e.g. the TCP/IP address is specified by "*" since this gets expanded to the known list of interfaces.
Remove the given server instance server entirely from the list of enqueued sockets. This means to delete it from each server socket on the one hand and to shutdown every child client spawned from this server on the other hand.
Return an array of port configurations to which the given server instance
server is currently bound to or NULL
if there is no such
binding. The caller is responsible for freeing the returned array by
running svz_array_destroy()
.
Return a static text representation of the server instance's server current port configuration bindings.
Return an array of listening socket structures to which the given server
instance server is currently bound to or NULL
if there is
no such binding. The calling function is reponsible for destroying the
returned array via svz_array_destroy()
.
This function checks if the given server instance server is bound to the listening socket structure sock and returns non-zero if it is the only server instance bound to this socket. Otherwise the routine returns zero.
This function attaches the given server instance server to the listening socket structure sock. It returns zero on success and non-zero if the server is already bound to the socket.
Removes the server instance server from the listening socket structure sock and returns the remaining number of servers bound to the socket structure.
Returns a socket structure representing a listening server socket with
the port configuration port. If there is no such socket with this
kind of port configuration yet then NULL
is returned.
This functions goes through the list of listening server socket
structures and returns an array of matching socket structures for the
given port configuration port. The caller is responsible for
freeing the array by running svz_array_destroy()
. If there are
no such listening server socket structures NULL
is returned.
Creates and returns a listening server socket structure. The kind of
listener which gets created depends on the given port configuration
port which must be a duplicated copy of one out of the list of
known port configurations. On success the function enqueues the
returned socket structure and assigns the port configuration. Initially
there are no bindings. In case of an error the given port configuration
is freed and NULL
is returned.
Returns the binding array of the listening server socket structure
sock or NULL
if there are no such bindings.
Returns the array of server instances bound to the listening socket
structure sock or NULL
if there are no bindings. The caller
is responsible for freeing the returned array by running
svz_array_destroy()
.
Creates a bind structure. The binding contains the given server instance server and the port configuration port. The caller is responsible for freeing the returned pointer.
Destroys the given binding binding. This includes the explicit
destruction of the port configuration. If binding is NULL
no operation is performed.
This function checks whether the server instance binding binding is part of one of the bindings in the array bindings and returns non-zero if so. Otherwise zero is returned.
This function adds the bindings stored in the listening server socket
structure sock to the binding array bindings and returns the
resulting array. If bindings is NULL
a new array is created.
If the socket structure sock is not a listening server socket
structure no operation is performed.
Goes through the listening server sockets sock bindings and checks
whether it contains the given binding consisting of server and
port. If there is no such binding yet NULL
is returned
otherwise the appropriate binding.
Searches through the bindings of the given listening server socket
structure sock and checks whether the server instance server
is bound to this socket structure. The function returns these binding and
returns NULL
otherwise. The caller is responsible for freeing
the returned array.
This function checks whether the given server instance server is bound to the server socket structure sock. Returns zero if not and non-zero otherwise.
This is the accept filter for the listening server socket structures
sock with pipe port configurations. It returns all bindings. The
caller is responsible for freeing the returned array by running
svz_array_destroy()
.
This is the accept filter for the listening server socket structures
sock with network port configurations. It returns the bindings
allowed to be accepted. The caller is responsible for freeing the returned
array by running svz_array_destroy()
. Which of the bindings are
allowed depends on the network interface address addr and the
network port port.
This is the main filter routine running either
svz_binding_filter_net()
or svz_binding_filter_pipe()
depending on the type of port configuration the given socket sock
contains.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Initial value: 0
When svz_nuke_happened is set to a non-zero value, the server
will terminate its main loop.
svz_child_died is set to a non-zero value whenever the server receives a SIGCHLD signal.
This holds the time on which the next call to svz_periodic_tasks()
should occur.
Set the name of the executable file which uses the core library. This
is usually argv[0]
.
This routine gets called once a second and is supposed to perform any task that has to get scheduled periodically. It checks all sockets' timers and calls their timer functions when necessary.
Initial value: NULL
svz_sock_root is the pointer to the head of the list of sockets,
which are handled by the server loop.
Initial value: NULL
svz_sock_last always points to the last structure in the socket queue
and is NULL when the queue is empty.
Return the socket structure for the socket id id and the version
version or NULL
if no such socket exists. If version
is -1 it is not checked.
Mark socket sock as killed. That means that no operations except disconnecting and freeing are allowed anymore. All marked sockets will be deleted once the server loop is through.
Enqueue the socket sock into the list of sockets handled by the server loop.
Remove the socket sock from the list of sockets handled by the server loop.
Do everything to shut down the socket sock. The socket structure gets removed from the socket queue, the file descriptor is closed and all memory used by the socket gets freed. Note that this function calls the sock's disconnect handler if defined.
Shutdown all sockets within the socket list no matter if it was scheduled for shutdown or not.
Set the sockets child parent to the given socket structure parent. This should be called whenever a listener accepts a connection and creates a new child socket.
Return the sockets child parent socket structure or NULL
if this socket does not exist anymore. This might happen if a listener
dies for some reason.
Set the referring socket structure of sock to the given socket
referrer. This can be used to create some relationship between
two socket structures. If referrer is NULL
the reference
will be invalidated.
Get the referrer of the socket structure sock. Return NULL
if there is no such socket.
Return the parents port configuration of the socket structure sock
or NULL
if the given socket has no parent, i.e. is a listener.
Go through each socket structure in the chained list.
Goes through the chained list of socket structures and filters each listener.
This routine checks the connection frequency of the socket structure child for the port configuration of the listener socket structure parent. Returns zero if the connection frequency is valid, otherwise non-zero.
This function returns zero if the child socket is allowed to connect to the port configuration of the parent socket structure which needs to be a listener therefore.
Create the socket lookup table initially. Must be called from
svz_boot()
.
Destroy the socket lookup table finally. Must be called from
svz_halt()
.
Goes through all socket and shuts invalid ones down.
Goes through the list of socket structures and checks whether each
pid
stored in a socket structure has died. If so, the
child_died
callback is called. If this callback returned non-zero
the appropriate socket structure gets scheduled for shutdown.
This routine checks whether the child process specified by the pid
handle stored in the socket structure sock is still alive. It
returns zero if so, otherwise (when the child process died) non-zero. This
routine is called from svz_sock_check_children()
.
Setup signaling for the core library.
Deinstall signaling for the core library.
Handle some signals to handle server resets (SIGHUP), to ignore broken pipes (SIGPIPE) and to exit gracefully if requested by the user (SIGINT, SIGTERM).
Prepare library so that svz_strsignal()
works. Called
from svz_boot()
.
The function svz_strsignal()
does not work afterwards anymore.
Called from svz_halt()
.
Resolve the given signal number to form a describing string. This function is reentrant, use it from the signal handler. It does not return NULL. The returned pointer is shared amongst all users. For unknown signals (which is not supposed to happen) the returned string points to a statically allocated buffer (which destroys the reentrance, of course) [who cares :-].
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This paragraph describes the main server loop functionality. There two modes of operation. The default mode as used in serveez is to jump into the loop and waiting until the core library drops out of it. The user can also tell the serveez core library to pass its socket chain once and return immediately. Thus you are able to issue additional functionality in between each pass if you cannot handle this within the timers (notifiers) of servers and sockets.
Check the server and client sockets for incoming connections and data, and process outgoing data.
Call this function once before using svz_loop_one()
.
Call this function once after using svz_loop_one()
.
Main server loop. Handle all signals, incoming and outgoing connections and listening server sockets.
This routine handles all things once and is called regularly in the
below svz_loop()
routine.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The next section deals with creating and handling listeners. The functions below provide the default routines invoked when accepting a new connection on a listener. This is necessary for connection oriented protocols (TCP and named pipes) only.
Create a listening server socket (network or pipe). port is the
port configuration to bind the server socket to. Return a NULL
pointer on errors.
Something happened on the a server socket, most probably a client
connection which we will normally accept. This is the default callback
for read_socket
for listening tcp sockets.
Check if client pipe is connected. This is the default callback for
idle_func
for listening pipe sockets.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A port configuration is a structure defining a network or file system configuration. Depending on the type of a server it can be bound to one or more port configurations. There are two major types of port configurations: connection and packet oriented protocol port configurations. TCP and PIPE configurations are connection oriented and ICMP, UDP and RAW configurations are packet oriented.
Serveez holds a list of port configurations. Each configuration is identified by its name. When you bind a server to a port configuration it does not get bound to a certain name but to its content. If there are two or more port configuration specifying the same network or file system configuration just a single one gets actually used.
Create a new blank port configuration.
Check if two given port configurations structures are equal i.e.
specifying the same network port or pipe files. Returns
PORTCFG_EQUAL
if a and b are identical,
PORTCFG_MATCH
if the network address ofeither port
configurations contains the other (INADDR_ANY match) and otherwise
PORTCFG_NOMATCH
or possibly PORTCFG_CONFLICT
.
Add the given port configuration port associated with the name
name to the list of known port configurations. Return NULL
on errors. If the return port configuration equals the given port
configuration the given one has been successfully added.
Remove the named port configuration identified by name from the
list of known port configurations. Return NULL
on errors or
otherwise the port configuration associated with name.
Return the port configuration associated with the given name name.
This function returns NULL
on errors.
This function makes the given port configuration port completely
unusable. No operation is performed if port is NULL
. If the
port configuration is part of the list of known port configurations it
it thrown out of them.
This function frees all resources allocated by the given port configuration port.
Delete the list of known port configurations. This routine should definitely called from the core library's finalizer.
Construct the sockaddr_in
fields from the ipaddr
field.
Returns zero if it worked. If it does not work the ipaddr
field
did not consist of an ip address in dotted decimal form.
Prepare the given port configuration port. Fill in default values for yet undefined variables.
Debug helper: Emit a printable representation of the the given port configuration to the given FILE stream f.
This function returns a simple text representation of the given port configuration port. The returned character string is statically allocated. Thus you cannot use it twice in argument lists.
Make a copy of the given port configuration port. This function
is used in svz_portcfg_expand()
.
Expand the given port configuration this if it is a network port
configuration and if the network ip address is INADDR_ANY
. Return
an array of port configurations which are copies of the given.
Return the pointer of the sockaddr_in
structure of the given
port configuration port if it is a network port configuration.
Otherwise return NULL
.
Return the UDP or TCP port of the given port configuration or zero if it neither TCP nor UDP.
Return the pointer to the ip address ipaddr
of the given
port configuration port if it is a network port configuration.
Otherwise return NULL
.
This macro returns the network device name stored in the given port
configuration port if it is a network port configuration. The
returned pointer can be NULL
if there is no such device set
or if the port configuration is not a network port configuration.
This function can be used to set the character string representation of a the port configuration this in dotted decimal form (ipaddr). Returns zero on success, non-zero otherwise.
Destroy the list of connections for each ip address ever connected to the given port configuration port.
Destroy the deny and allowed access list of the given port configuration port.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section contains the description of some runtime checkable flags
indicating the abilities of the running serveez core API and the underlying
operating system. It also describes the most important functions
svz_boot()
and svz_halt()
which must be the first and the last
call to the core API.
Initial value: { NULL, 0, 0, 0 }
The configuration structure of the core library.
Initial value: "serveez"
The symbolic name of the core library.
Initial value: __serveez_version
The version of the core library.
Initial value: __serveez_timestamp
Timestamp when core library has been build.
Initial value: 1
Runtime flag if this is the debug version or not.
Initial value: 1
Runtime flag if this is Win32 or not.
Initial value: 1
Runtime checkable flags for configuration language and code if flood
protection has been enabled or not.
This routine has to be called once before you could use any of the serveez core library functions.
Shutdown the serveez core library.
Initialization of the configuration.
Initialization of the core library.
Finalization of the core library.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The network interface functions of the serveez core API allow the access to the network devices on your system. The system administrator can setup these devices to be bound to different Internet addresses and thereby split the network configuration into different "domains". Thus the system is able to separate traffic of different networks. If setup correctly serveez can follow these rules.
Initial value: NULL
The available interface list.
Print the text representation of all the network interfaces.
Collect all available network interfaces and put them into the list
svz_interfaces. This is useful in order to bind()
server
sockets to specific network interfaces. Thus you can make certain
services accessible from "outside" or "inside" a network installation
only.
Free the network interface list.
Add a network interface to the current list of known interfaces. Drop duplicate entries. The given arguments index specifies the network interface index number, desc an interface desription, addr the IP address in network byte order and the detected flag if the given network interface has been detected by Serveez itself or not.
This function returns the interface structure for the given IP address
addr if any. Returns NULL
otherwise.
The following function returns a network interface structure for a given
interface name (e.g. eth0). If no such interface exists it returns
NULL
.
This function checks for network interface changes. It emits messages for
new and removed interfaces. Software interfaces which have not been
detected by Serveez stay untouched. If Serveez receives a SIGHUP
signal the signal handler runs it once.
Iteration macro for the list of known network interfaces. If any each interface gets assigned to ifc. The variable i is the iteration variable.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Serveez is meant to run on Windows systems as well (with some restrictions of course). The following functions come up with the Windows implementation of the serveez core API only. They allow access to the Windows registry database and some other useful things.
Start the windows daemon thread and detach from the current console.
Stop the windows daemon thread.
Convert an ASCII string into a UNICODE string.
Convert a UNICODE string into an ASCII string.
Read an unsigned integer value from the Windows Registry Database.
Write an unsigned integer value to the Windows Registry Database.
Read a string value from the Windows Registry Database.
Write a string value to the Windows Registry Database.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on November, 1 2009 using texi2html 1.76.