summaryrefslogtreecommitdiffstats
path: root/serial/manager.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-05-09 22:38:56 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-05-09 22:38:56 +0000
commitd997f1912250982b6b7e4eae7516245c9be291b7 (patch)
tree194d8c9bceda3d6c147ef03a240dfcfbd87bb0f0 /serial/manager.c
parent86477ad9060c5456a394af462e17247ee51779ed (diff)
serial: handle connection refused error and others SO_ERROR properly
Diffstat (limited to 'serial/manager.c')
-rw-r--r--serial/manager.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/serial/manager.c b/serial/manager.c
index 90637123..0c2baba9 100644
--- a/serial/manager.c
+++ b/serial/manager.c
@@ -401,14 +401,7 @@ static gboolean rfcomm_connect_cb(GIOChannel *chan,
char node_name[16];
const char *pname = node_name;
struct rfcomm_dev_req req;
- int sk, ret, err, fd;
- socklen_t len;
-
- if (cond & (G_IO_ERR | G_IO_HUP)) {
- error("Hangup or error on rfcomm socket");
- err_connection_canceled(pc->conn, pc->msg);
- goto fail;
- }
+ int sk, err, fd;
if (pc->canceled) {
err_connection_canceled(pc->conn, pc->msg);
@@ -417,17 +410,28 @@ static gboolean rfcomm_connect_cb(GIOChannel *chan,
sk = g_io_channel_unix_get_fd(chan);
- len = sizeof(ret);
- if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &ret, &len) < 0) {
- err = errno;
- error("getsockopt(SO_ERROR): %s (%d)", strerror(err), err);
- err_connection_failed(pc->conn, pc->msg, strerror(err));
- goto fail;
- }
+ if (cond & (G_IO_ERR | G_IO_HUP)) {
+ socklen_t len;
+ int ret;
+
+ len = sizeof(ret);
+ if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &ret, &len) < 0) {
+ err = errno;
+ error("getsockopt(SO_ERROR): %s (%d)",
+ strerror(err), err);
+ err_connection_failed(pc->conn,
+ pc->msg, strerror(err));
+ goto fail;
+ }
- if (ret != 0) {
- error("connect(): %s (%d)", strerror(ret), ret);
- err_connection_failed(pc->conn, pc->msg, strerror(ret));
+ if (ret != 0) {
+ error("connect(): %s (%d)", strerror(ret), ret);
+ err_connection_failed(pc->conn, pc->msg, strerror(ret));
+ goto fail;
+ }
+
+ error("Hangup on rfcomm socket");
+ err_connection_canceled(pc->conn, pc->msg);
goto fail;
}