diff options
author | beber <beber> | 2005-12-02 11:34:14 +0000 |
---|---|---|
committer | beber <beber> | 2005-12-02 11:34:14 +0000 |
commit | 7951726fe3f633704d0045c83b833e00e237100b (patch) | |
tree | a8e36162359ba9dd8205109c237cb7843ba61b22 /src | |
parent | Have a better input parser (diff) | |
download | espik-7951726fe3f633704d0045c83b833e00e237100b.tar.xz |
add handler for when we get connected and disconnect
also see if connection is unavailable
Diffstat (limited to 'src')
-rw-r--r-- | src/espik_net.c | 30 | ||||
-rw-r--r-- | src/espik_net.h | 1 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/espik_net.c b/src/espik_net.c index 058f153..914f9d5 100644 --- a/src/espik_net.c +++ b/src/espik_net.c @@ -16,6 +16,7 @@ typedef int (*Handler_Func) (void* data, int ev_type, void* ev); static int ret; /* For debug */ +static char connected = 0; Ecore_Con_Server* con_sock; @@ -33,16 +34,36 @@ void espik_con_init (t_info serv_info) serv_info.server->host, (int)serv_info.server->port, NULL); if (!con_sock) { - fprintf (stderr, "ecore_con_server_connect failed\n"); + fprintf (stderr, "ecore_con_server_connect failed (ECORE_CON_REMOTE_SYSTEM)\n"); exit (-1); } if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL))) { - fprintf (stderr, "ecore_event_handler_add failed at %s\n", __FUNCTION__); + fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA) failed at %s\n", __FUNCTION__); exit (-1); } + + if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, + (Handler_Func) espik_con_up, NULL))) + { + fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD) failed at %s\n", __FUNCTION__); + exit (-1); + } + + if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, + (Handler_Func) espik_con_shutdown, NULL))) + { + fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL) failed at %s\n", __FUNCTION__); + exit (-1); + } +} + +void espik_con_up() +{ + printf ("Connected\n"); + connected = 1; } void espik_con_shutdown () @@ -51,13 +72,16 @@ void espik_con_shutdown () /* printf ("> espik_con_shutdown\n"); */ #endif + if (connected == 0) + fprintf (stderr, "Unable to connect to server\n"); + ecore_con_server_del (con_sock); ecore_con_shutdown (); #if _ESPIK_DEBUG_ /* printf ("< espik_con_shutdown\n"); */ #endif - /* ecore_main_loop_quit (); */ + ecore_main_loop_quit (); } void espik_raw_send (char *msg) diff --git a/src/espik_net.h b/src/espik_net.h index 03d50c2..3e45c3a 100644 --- a/src/espik_net.h +++ b/src/espik_net.h @@ -5,6 +5,7 @@ void espik_raw_send (char*); void espik_con_init (t_info); +void espik_con_up(); void espik_con_shutdown (); #endif /* HAVE_ESPIK_NET_H */ |