#include <gtcutils.h>
#include <unistd.h>
#include <sys/types.h>
Go to the source code of this file.
Compounds | |
| struct | _gtcClient |
| On the server, this is the representation for a single client. More... | |
| struct | _gtcHost |
| A simple host. More... | |
| struct | _gtcPacketList |
| A list of packets. More... | |
| struct | _gtcServerMessage |
| struct | _gtcSpeakerNode |
| List of gtcSpeaker in the server, refcounted. More... | |
| struct | gtcPacket |
| Packets of data. More... | |
| struct | gtcServer |
| A server. More... | |
| struct | gtcSpeaker |
| The basic communication object. More... | |
Typedefs | |
| typedef unsigned char | gtcByte |
| A byte. Maybe this should go somewhere else (gtcutils.h?). | |
| typedef struct _gtcPacketList | gtcPacketList |
| A list of packets. | |
| typedef struct _gtcSpeakerNode | gtcSpeakerNode |
| A gtcSpeakerNode. | |
| typedef struct _gtcHost | gtcHost |
| A host. | |
| typedef struct _gtcClient | gtcClient |
| typedef struct _gtcServerMessage | gtcServerMessage |
Enumerations | |
| enum | gtcServerMessages { gtcNewClient = 0, gtcDeadClient = 1, gtcReceivedPacket = 2, gtcReadyForSending = 3, gtcTimeout = 4, gtcNoMessage } |
| These are the types of gtcServerMessage you can get. More... | |
| enum | gtcClientMessages { gtcKeyRepeat = 0, gtcKeyPress, gtcKeyRelease, gtcConfigureNotify, gtcButtonPress, gtcButtonRelease, gtcNOP } |
Functions | |
| void | gtc_set_non_block (int filedes) |
| This puts a socket into a low latency non-blocking mode. | |
| gtcSpeaker* | gtc_connect_2_host (char *host, int port) |
| Connects to the specified host and port, calls gtc_set_non_block(). | |
| gtcSpeaker* | gtc_connect_2_fd (int fd) |
| Connects to an existing filedescriptor, calls gtc_set_non_block(). | |
| void | gtc_speaker_destroy (gtcSpeaker *foo) |
| Destroys and cleans up a speaker, does NOT close the fd (why???). | |
| void | gtc_speaker_read (gtcSpeaker *s) |
| If select() says a speaker's fd needs reading, call this. | |
| void | gtc_speaker_write (gtcSpeaker *s) |
| If select() says a speaker's fd needs writing, call this. | |
| int | gtc_speaker_long_out_queue (gtcSpeaker *s) |
| Returns 1 if there's more than one outgoing packet in the output queue. | |
| gtcPacket* | gtc_speaker_get (gtcSpeaker *s) |
| Get the next available packet, return 0 if none are available. See also gtc_speaker_read(). | |
| void | gtc_speaker_put (gtcSpeaker *s, gtcPacket *p) |
| Put a packet in the outgoing queue. See also gtc_speaker_write(). | |
| gtcPacket* | gtc_alloc_packet (int size) |
| Allocate a packet, refcount is 0. | |
| gtcPacket* | gtc_make_packet (gtcByte *data, int size) |
| Allocate and copy data to the packet. | |
| void | gtc_destroy_packet (gtcPacket *p) |
| Destroy packet, ignoring refcount. | |
| void | gtc_upcount_packet (gtcPacket *p) |
| Adds 1 to the refcount (uhhh). | |
| void | gtc_downcount_packet (gtcPacket *p) |
| Decreases the refcount and calls gtc_destroy_packet() if it reaches 0. | |
| void | gtc_speaker_fds (gtcSpeaker *s, fd_set *readfds, fd_set *writefds) |
| Set the fd_sets properly for a select. Does not destroy what's already in the fd_sets. | |
| void | gtc_print_packet (gtcPacket *p) |
| Print out the packet as hex. | |
| gtcHost* | gtc_new_host_by_fd (int fd, int verbose) |
| Assuming fd is a listen socket, this will create an appropriate host. | |
| gtcHost* | gtc_new_host (int port, int verbose) |
| Main way to create a host. More... | |
| void | gtc_host_fds (gtcHost *h, fd_set *readfds, fd_set *writefds) |
| Set fd_sets. More... | |
| void | gtc_host_process (gtcHost *h, fd_set *readfds, fd_set *writefds) |
| Do some host work. More... | |
| void | gtc_kill_host (gtcHost *h) |
| Frees a host and associated resources. | |
| void | gtc_speaker_node_destroy (gtcSpeakerNode *node) |
| This does the refcount stuff to a gtcSpeakerNode, to destroy them. | |
| gtcServer* | gtc_server_new (int port, int verbose, int sizeofclient, double sec_per_byte) |
| Creates a new server. More... | |
| void | gtc_server_delete (gtcServer *s) |
| gtcServerMessage* | gtc_server_get_message (gtcServer *s, double timeout) |
| Get the next message from the server. More... | |
| void | gtc_server_next_message (gtcServer *s, double timeout, gtcServerMessage *msg) |
| Get and copy the next message from the server. More... | |
| void | gtc_client_put (gtcClient *c, gtcPacket *p) |
| Send a packet to a client. More... | |
| void | gtc_client_delete (gtcClient *c) |
| Frees resources associated with a client. More... | |
Variables | |
| int | gtcSpeakerverbose = 0 |
| Set this to get a lot of debug output. | |
This include file handles low level socket stuff. It will open a socket for you, will send packets in a safe way, do everything in a non-blocking way. It also disable nagle (the buffering algorithm enabled by default on TCP connection). Even though TCP is used (and not UDP), I'm getting very good performance out of this.
|
|
|
Frees resources associated with a client. You need to call this when a client dies and you're done processing it. It will free up all relevant resources. If you've extended the gtcClient structure (by having the gtcServer allocate more bytes than sizeof(gtcClient)), and if you've stored pointers in this extra data, and if these pointers need freeing, do this _before_ calling gtc_client_delete(). |
|
|
Send a packet to a client. This is the same as gtc_speaker_put() but it also takes care of the bandwidth stuff. |
|
|
Set fd_sets. For use with select(3). Call this to see which filedescriptors you need to be waiting on. FD_ZERO is not called on readfds or writefds, this allows you to wait on other filedescriptors as well. Upon return of select, you will pass the returning readfds and writefds to gtc_host_process(). |
|
|
Do some host work. Once you've called gtc_host_fds(), followed by select(3), call this to process any new information that the clients may have received, as well as send data to clients who want it. |
|
|
Main way to create a host. You give it the desired port and a verbosity level. It will attempt to get a host for you. If any errors occur, a zero pointer is returned (baad). |
|
|
Get the next message from the server. This gets the next available message from the server. If none are available, the process will sleep until it can get some messages. I don't like grabbing the main loop any more than the next guy, but it is pretty convenient. Also, for X11, you can just select the X11 socket and that's reliable, you don't actually have to sleep on your XNextEvent. However, with this server crap, there are zillions of fds to wait on and they can change all the time. When a client dies, you will receive a gtcDeadClient message and you are responsible to free the gtcClient structure by calling gtc_client_delete(). Otherwise, the only cleanup you need to do is to free() the gtcServerMessage. Parameter timeout specifies how long you're willing to wait for a message. The length of time is in seconds, zero means that you will get pending messages but not block for any new messages, and a negative value means that it should block forever or until a new message comes in. |
|
|
Creates a new server. To get a new server, call this function with the port to listen to. Verbosity can be set to get messages on stdout (or maybe stderr), 0 is silent. sizeofclient is used to specify an optionally larger size to the gtcClient structure (for you to store your private information if you need). A value of 0 will result in the default sizeof(gtcClient) being used, while a nonzero value less than sizeof(gtcClient) should cause an error. The parameter sec_per_byte is the default bandwidth allocated to each client. There isn't yet a global bandwidth control for the server. When clients connect, the gtcClient.sec_per_byte value will be set as per the server's default_sec_per_byte value, which is specified in this parameter. If you set this to zero, bandwidth control is disabled (and you will never get gtcReadyForSending messages.) |
|
|
Get and copy the next message from the server. This is essentially the same as gtc_server_get_message() except that the message gets copied to a buffer you own, so there is a priori nothing to free() afterwards. For instance, if parameter msg points to a stack variable, then no freeing (except perhaps for calling gtc_client_delete()) is required. |
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001