Zex
08-05-2006, 02:55 AM
Hello, Ive got a question reguarding some socket programming that Im hoping someone might be able to offer an example for, or something to that extent.
As it stands I've got a linked list of pointers that look like this:
struct descriptor_data
{
DESCRIPTOR_DATA *next;
DESCRIPTOR_DATA *prev;
CHAR_DATA *character;
struct sockaddr_in client;
char *input;
char *output;
int nanny;
int connected;
int fd;
int idle;
};
In the main loop for the program, I accept connections, add new entries to the linked list, set a socket on fd, and a few other things. The question I find myself asking is in reguards to reading and writing to this descriptor.
Theorhetically it'd look something like
for( descriptor = first_descriptor; descriptor; descriptor = descriptor->next )
{
descriptor_input( descriptor );
descriptor_output( descriptor );
}
( Let's pretend ).
The contents of descriptor_input and _output should have 'read()' and 'write()', but beyond that I'm clueless as to how to handle the situation. Not many library definitions for the functions that I have found are very helpful, so i decided to see if I couldnt find some help here. If someone could give me an example for socket reading and writing I'de appreciate it, big reason I dont know how to handle this is because I dont have any good examples on socket use. Again, thank you.
As it stands I've got a linked list of pointers that look like this:
struct descriptor_data
{
DESCRIPTOR_DATA *next;
DESCRIPTOR_DATA *prev;
CHAR_DATA *character;
struct sockaddr_in client;
char *input;
char *output;
int nanny;
int connected;
int fd;
int idle;
};
In the main loop for the program, I accept connections, add new entries to the linked list, set a socket on fd, and a few other things. The question I find myself asking is in reguards to reading and writing to this descriptor.
Theorhetically it'd look something like
for( descriptor = first_descriptor; descriptor; descriptor = descriptor->next )
{
descriptor_input( descriptor );
descriptor_output( descriptor );
}
( Let's pretend ).
The contents of descriptor_input and _output should have 'read()' and 'write()', but beyond that I'm clueless as to how to handle the situation. Not many library definitions for the functions that I have found are very helpful, so i decided to see if I couldnt find some help here. If someone could give me an example for socket reading and writing I'de appreciate it, big reason I dont know how to handle this is because I dont have any good examples on socket use. Again, thank you.