summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-11-05 17:19:37 +0200
committerJohan Hedberg <johan.hedberg@nokia.com>2008-11-05 17:19:37 +0200
commitf9c392c96afcb7426a534447d5571b618f39b2b2 (patch)
tree79da002c2663059dfdcbcb6f0a5f9b13899aa32c
parenta11c92d7da3a3b7890ad7aa75b69ed97ebac1b0c (diff)
downloadobexd-f9c392c96afcb7426a534447d5571b618f39b2b2.tar.gz
Try to reopen the tty once if the connection gets dropped
This ensures that we're back monitoring the tty in case the client sends a OBEX Disconnect which in the current code always does a OBEX_TransportDisconnect. This patch is also preparation for the next step where we should be able to re-initialize the tty through some external trigger (e.g. a SIGUSR1 signal).
-rw-r--r--src/main.c5
-rw-r--r--src/obex.c23
-rw-r--r--src/obex.h4
3 files changed, 29 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 4a3ac46..07dad2d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,8 +59,8 @@
static GMainLoop *main_loop = NULL;
-static int tty_init(int services, const gchar *root_path,
- const gchar *capability, const gchar *devnode)
+int tty_init(int services, const gchar *root_path,
+ const gchar *capability, const gchar *devnode)
{
struct server *server;
struct termios options;
@@ -83,6 +83,7 @@ static int tty_init(int services, const gchar *root_path,
server->folder = g_strdup(root_path);
server->auto_accept = TRUE;
server->capability = g_strdup(capability);
+ server->devnode = g_strdup(devnode);
ret = obex_session_start(fd, server);
if (ret < 0) {
diff --git a/src/obex.c b/src/obex.c
index 4768cdf..7197c94 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -881,6 +881,7 @@ void server_free(struct server *server)
g_free(server->name);
g_free(server->folder);
g_free(server->capability);
+ g_free(server->devnode);
g_free(server);
}
@@ -907,6 +908,17 @@ static void obex_handle_destroy(gpointer user_data)
OBEX_Cleanup(obex);
}
+static gboolean tty_reinit(gpointer data)
+{
+ struct server *server = data;
+
+ tty_init(server->services, server->folder, server->capability, server->devnode);
+
+ server_free(server);
+
+ return FALSE;
+}
+
static gboolean obex_handle_input(GIOChannel *io,
GIOCondition cond, gpointer user_data)
{
@@ -915,8 +927,17 @@ static gboolean obex_handle_input(GIOChannel *io,
if (cond & G_IO_NVAL)
return FALSE;
- if (cond & (G_IO_HUP | G_IO_ERR))
+ if (cond & (G_IO_HUP | G_IO_ERR)) {
+ struct obex_session *os;
+
+ error("HUP");
+
+ os = OBEX_GetUserData(obex);
+ if (os->server->devnode)
+ g_idle_add(tty_reinit, os->server);
+
return FALSE;
+ }
if (OBEX_HandleInput(obex, 1) < 0) {
error("Handle input error");
diff --git a/src/obex.h b/src/obex.h
index 6718942..b9c1d67 100644
--- a/src/obex.h
+++ b/src/obex.h
@@ -52,6 +52,7 @@ struct server {
gchar *capability;
guint32 handle;
uint8_t channel;
+ gchar *devnode;
};
struct obex_session {
@@ -92,3 +93,6 @@ gboolean os_prepare_get(struct obex_session *os, gchar *file, guint32 *size);
gint os_prepare_put(struct obex_session *os);
void server_free(struct server *server);
+
+int tty_init(gint service, const gchar *folder, const gchar *capability,
+ const gchar *devnode);