[ENet-discuss] Core Dump at Server side on Abruptly killing the
Client using ctrl-C
Ulhas Dhuri.
ulhas.dhuri at gmail.com
Fri Aug 26 23:13:59 PDT 2005
Greetings!
I have gone through most of the ENet-discuss
Archives. I noted that
1>there are very example for newbies so I would like to hand over
this fragment as EXAMPLE.
2> NOW THE REAL PROBLEM
I got a core dump on my linux box at the SERVER side when I killed
the client with ^C.
The core is dumped in the enet_host_service() API
This could be the real life senario if the client is abruptly killed.
Also I would like to state that things work fine on client side if the
server was killed by ^C ie. there is no core dump on client side.
Now here is the stuff and the gdb's analysis of core dump
**********SERVER CODE***********************
bool connected = false;
if ( enet_initialize() != 0)
{
printf("enet_initialize()");
return EXIT_FAILURE;
}
ENetAddress address;
ENetHost * server;
ENetEvent event;
ENetPeer clientpeer; // NOTE need to use a array here n. client
//NOTE : IN SERVER SET THE ADDRESS 1st AND THEN CREATE THE SERVER
/* Bind the server to the default localhost. */
/* A specific host address can be specified by */
// address.host = ENET_HOST_ANY;
enet_address_set_host (& address, "192.168.0.204");
/* Bind the server to port 1234. */
address.port = 3333;
server = enet_host_create (& address /* the address to bind the
server host to */,
32 /* allow up to 32 clients and/or outgoing connections */,
0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */);
if (server == NULL)
{
fprintf (stderr,
"An error occurred while trying to create an ENet
server host.\n");
exit (EXIT_FAILURE);
}
while(1)
{
/* Wait up to 1000 milliseconds for an event. */
if (enet_host_service (server, & event, 1000) >= 0)
{
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf ("A new client connected from %x:%u.\n",
event.peer -> address.host,
event.peer -> address.port);
clientpeer = *(event.peer);
printf ("Stored Values of client peer %x:%u.\n",
clientpeer.address.host,
clientpeer.address.port);
connected = true;
/* Store any relevant client information here. */
char info[50]; strcpy(info,"Client Info");
event.peer -> data = info;
break;
case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s
was received from %s on ch
event.packet -> dataLength,
event.packet -> data,
event.peer -> data,
event.channelID);
/* Clean up the packet now that we're done using it. */
enet_packet_destroy (event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf ("%s disconected.\n", event.peer -> data);
/* Reset the peer's client information. */
event.peer -> data = NULL;
connected = false;
break;
case ENET_EVENT_TYPE_NONE :
//printf("\nReturned if no event occurred
within the specified time lim
break;
}
}
if(connected)
{
char myMsg[50];
strcpy(myMsg,"**** MSG FROM SERVER **** ");
// Create a reliable packet of size 7 containing "packet\0"
ENetPacket * newpacket = enet_packet_create (myMsg,
strlen (myMsg) + 1,
ENET_PACKET_FLAG_RELIABLE);
// Send the packet to the peer over channel id 3.
/* One could also broadcast the packet by */
/* enet_host_broadcast (host, 3, packet); */
enet_peer_send (&clientpeer,1 , newpacket);
//enet_host_flush(server);
}
}
enet_host_destroy(server);
enet_deinitialize();
return 0;
}
********************** CLIENT CODE **************************
if ( enet_initialize() != 0)
{
printf("enet_initialize()");
return EXIT_FAILURE;
}
ENetAddress address;
ENetHost * client;
ENetPeer *peer;
ENetEvent event;
////// CODE TO CREATE A CLIENT AND BIND IT
client = enet_host_create (NULL /* create a client host */,
1 /* only allow 1 outgoing connection */,
57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
if (client == NULL)
{
fprintf (stderr,
"An error occurred while trying to create an ENet
client host.\n");
exit (EXIT_FAILURE);
}
/* Connect to some.server.net:1234. */
enet_address_set_host (& address, "192.168.0.204");
address.port = 3333;
/* Initiate the connection, allocating the two channels 0 and 1. */
peer = enet_host_connect (client, & address, 2);
if (peer == NULL)
{
fprintf (stderr,
"No available peers for initiating an ENet connection.\n");
exit (EXIT_FAILURE);
}if (enet_host_service (client, & event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
{
puts ("Connection to 192.168.0.204:3333 succeeded.");
}
else
{
/* Either the 5 seconds are up or a disconnect event was */
/* received. Reset the peer in the event the 5 seconds */
/* had run out without any significant event. */
enet_peer_reset (peer);
puts ("Connection to 192.168.0.204:1234 failed.");
}
while(1)
{
/* Wait up to 100 milliseconds for an event. */
if(enet_host_service (client, & event, 100) > 0)
{
switch (event.type)
{
case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s
was received from %s on ch
event.packet -> dataLength,
event.packet -> data,
event.peer -> data,
event.channelID);
/* Clean up the packet now that we're done using it. */
enet_packet_destroy (event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf ("%s Remote Connection
disconected.\n", event.peer -> data);
/* Reset the peer's client information. */
event.peer -> data = NULL;
break;
}
if(event.type == ENET_EVENT_TYPE_DISCONNECT )
break;
}
char myMsg[100];
strcpy(myMsg,"**** MSG FROM CLIENT **** ");
// Create a reliable packet of size 7 containing "packet\0"
ENetPacket * packet = enet_packet_create (myMsg,
strlen (myMsg) + 1,
ENET_PACKET_FLAG_RELIABLE);
// Send the packet to the peer over channel id 3.
/* One could also broadcast the packet by */
/* enet_host_broadcast (host, 3, packet); */
enet_peer_send (peer, 0, packet);
enet_host_flush(client);
}
enet_host_destroy(client);
enet_deinitialize();
return 0;
}
####################### CORE DUMP ANALYSIS BY GDB ##################
(gdb) bt
#0 0x40178cef in _int_free () from /lib/i686/libc.so.6
#1 0x40177b4c in free () from /lib/i686/libc.so.6
#2 0x08049a18 in enet_peer_reset_outgoing_commands (queue=0xbffff748)
at peer.c:263
#3 0x08049af0 in enet_peer_reset_queues (peer=0x804ec28) at peer.c:298
#4 0x0804b371 in enet_protocol_check_timeouts (host=0x804d458, peer=0x804ec28,
event=0xbffff760) at protocol.c:918
#5 0x0804b86a in enet_protocol_send_outgoing_commands
(host=0x804d458, event=0xbffff760,
checkForTimeouts=1) at protocol.c:1063
#6 0x0804b928 in enet_host_service (host=0x804d458, event=0xbffff760,
timeout=4135067729)
at protocol.c:1189
#7 0x08048b25 in main (argc=1, argv=0xbffff7e4) at myServer.cpp:76
ITS SEEMS THAT THE SERVER WAS TRYING TO FREE SOME
UNSEND PACKET'S
Any IMMEDIATE help would be APPRECIATED
--
Warm Regards,
Ulhas . S . Dhuri
More information about the ENet-discuss
mailing list