BRL-CAD
|
Files | |
file | pkg.h |
Data Structures | |
struct | pkg_switch |
struct | pkg_header |
struct | pkg_conn |
Macros | |
#define | PKG_STDIO_MODE -3 |
#define | PKG_MAGIC 0x41FE |
#define | PKG_STREAMLEN (32*1024) |
#define | PKC_NULL ((struct pkg_conn *)0) |
#define | PKC_ERROR ((struct pkg_conn *)(-1L)) |
#define | pkg_send_vls(type, vlsp, pkg) pkg_send( (type), bu_vls_addr((vlsp)), bu_vls_strlen((vlsp))+1, (pkg) ) |
Typedefs | |
typedef void(* | pkg_callback) (struct pkg_conn *, char *) |
typedef void(* | pkg_errlog) (const char *msg) |
Variables | |
int | pkg_permport |
#define PKG_MAGIC 0x41FE |
#define pkg_send_vls | ( | type, | |
vlsp, | |||
pkg | |||
) | pkg_send( (type), bu_vls_addr((vlsp)), bu_vls_strlen((vlsp))+1, (pkg) ) |
|
extern |
Open a network connection to a host/server.
Returns PKC_ERROR on error.
Close a network connection.
Gracefully release the connection block and close the connection.
|
extern |
|
extern |
Suck all data from the operating system into the internal buffer.
This is done with large buffers, to maximize the efficiency of the data transfer from kernel to user.
It is expected that the read() system call will return as much data as the kernel has, UP TO the size indicated. The only time the read() may be expected to block is when the kernel does not have any data at all. Thus, it is wise to call call this routine only if:
a) select() has indicated the presence of data, or b) blocking is acceptable.
This routine is the only place where data is taken off the network. All input is appended to the internal buffer for later processing.
Subscripting was used for pkc_incur/pkc_inend to avoid having to recompute pointers after a realloc().
Returns - -1 on error 0 on EOF 1 success
Send a message on the connection.
Send the user's data, prefaced with an identifying header which contains a message type value. All header fields are exchanged in "network order".
Note that the whole message (header + data) should be transmitted by TCP with only one TCP_PUSH at the end, due to the use of writev().
Returns number of bytes of user data actually sent.
|
extern |
Send a two part message on the connection.
Exactly like pkg_send, except user's data is located in two disjoint buffers, rather than one. Fiendishly useful!
Send a message that doesn't need a push.
Exactly like pkg_send except no "push" is necessary here. If the packet is sufficiently small (MAXQLEN) it will be placed in the pkc_stream buffer (after flushing this buffer if there insufficient room). If it is larger than this limit, it is sent via pkg_send (who will do a pkg_flush if there is already data in the stream queue).
Returns number of bytes of user data actually sent (or queued).
|
extern |
Empty the stream buffer of any queued messages.
Flush any pending data in the pkc_stream buffer.
Returns < 0 on failure, else number of bytes sent.
Wait for a specific msg, user buf, processing others.
This routine implements a blocking read on the network connection until a message of 'type' type is received. This can be useful for implementing the synchronous portions of a query/reply exchange. All messages of any other type are processed by pkg_block().
Returns the length of the message actually received, or -1 on error.
Wait for specific msg, malloc buf, processing others.
This routine implements a blocking read on the network connection until a message of 'type' type is received. This can be useful for implementing the synchronous portions of a query/reply exchange. All messages of any other type are processed by pkg_block().
The buffer to contain the actual message is acquired via malloc(), and the caller must free it.
Returns pointer to message buffer, or NULL.
|
extern |
Wait until a full message has been read.
This routine blocks, waiting for one complete message to arrive from the network. The actual handling of the message is done with _pkg_dispatch(), which invokes the user-supplied message handler.
This routine can be used in a loop to pass the time while waiting for a flag to be changed by the arrival of an asynchronous message, or for the arrival of a message of uncertain type.
The companion routine is pkg_process(), which does not block.
Control returns to the caller after one full message is processed. Returns -1 on error, etc.
|
extern |
Become a transient network server
Become a one-time server on a given open connection. A client has already called and we have already answered. This will be a servers starting condition if he was created by a process like the UNIX inetd.
Returns PKC_ERROR or a pointer to a pkg_conn structure.
|
extern |
Create a network server, and listen for connection.
We are now going to be a server for the indicated service. Hang a LISTEN, and return the fd to select() on waiting for new connections.
Returns fd to listen on (>=0), -1 on error.
|
extern |
Create network server from IP address, and listen for connection.
We are now going to be a server for the indicated service. Hang a LISTEN, and return the fd to select() on waiting for new connections.
Returns fd to listen on (>=0), -1 on error.
|
extern |
As permanent network server, accept a new connection
Given an fd with a listen outstanding, accept the connection. When poll == 0, accept is allowed to block. When poll != 0, accept will not block.
Returns - >0 ptr to pkg_conn block of new connection PKC_NULL accept would block, try again later PKC_ERROR fatal error
returns a human-readable string describing this version of the LIBPKG library.
|
extern |