Greetings, I am trying to create a program which works with both Sockets and pthreads. The application listens on a specified TCP port and once a request is made it opens up two pthreads, one which parses the incoming data and places the information on a queue, and another that actually processes the information placed on the queue.
My Problem is that once I send data to the socket and the program reads from the socket it crashes with the output "Killed"... I cannot figure out why it is doing this. any ideas?
Here is the output from the program:
$ ./pp
queueInit: Queue Creation Successful.
Socket listening on port '3333'
Server Message: Awaiting socket request.
Server Message: Request acknowledged, processing packet...
Thread [16386] Created.
Thread [32771] Created.
Process Packet Subroutine: Queue EMPTY ... Waiting
Data Received: 192.168.2.11:80:>:192.168.2.1:80:S
Killed
$
As you can see It can open the port fine for listening, accept the data I send in the packet and output the data received ('192.168.2.11:80:>:192.168.2.1:80:S' is the data sent.) and then all of a sudden it simply crashes out with the output Killed.
Below is the relevant code,
//------------------------------------------> main()
...
for( ; ; )
{
client = sizeof( client_addr );
printf("Server: Awaiting request.\n");
newsocket = accept( socket, (struct sockaddr *) &client_addr, &client_socket );
printf("Server Message: Request acknowledged, processing request.\n");
pthread_create( &extractor, NULL, extract_info, q );
pthread_create( &process, NULL, process_packet, q );
pthread_join( extractor, NULL );
pthread_join( process, NULL );
}
...
//----------------------------------------->extract_info( void *fifo )
{
char data[MAX_INPUT_LENGTH];
input_t *input;
input = (input_t *) malloc( sizeof( input_t * ) );
queue *q;
q = (queue *) fifo;
printf("Thread [%d] Created.\n", pthread_self() );
/* Read from the socket - retreive packet information */
read( newsocket, &data, MAX_INPUT_LENGTH );
printf("Data Received: %s\n", data );
printf(" TEST?? " );
...
}
Note : that the program is able to print the Data Received .. Line.. however, it crashes before ever printing the "TEST??" ... As well, if I take out the data received line it does not print the TEST?? line.. it simply crashes out with "killed" again.
Thanks for your time in advance. Any Comments / Suggestions welcome.
by: AxterPosted on 2005-09-08 at 09:43:31ID: 14846052
>>input = (input_t *) malloc( sizeof( input_t * ) );
The above line of code will only allocate enough memory for the size of the pointer.
It should be the following:
input = (input_t *) malloc( sizeof( input_t ) );