Lines 1-10
Link Here
|
1 |
--- gsmlib/gsm_unix_serial.cc.orig Thu Jul 17 20:44:42 2003 |
1 |
--- gsmlib/gsm_unix_serial.cc.orig Sun Sep 22 20:51:10 2002 |
2 |
+++ gsmlib/gsm_unix_serial.cc Thu Jul 17 20:44:54 2003 |
2 |
+++ gsmlib/gsm_unix_serial.cc Wed Aug 18 01:27:08 2004 |
3 |
@@ -16,6 +16,7 @@ |
3 |
@@ -20,6 +20,7 @@ |
4 |
#include <gsmlib/gsm_nls.h> |
|
|
5 |
#include <gsmlib/gsm_unix_serial.h> |
6 |
#include <gsmlib/gsm_util.h> |
7 |
+#include <assert.h> |
8 |
#include <termios.h> |
9 |
#include <fcntl.h> |
4 |
#include <fcntl.h> |
10 |
#include <iostream> |
5 |
#include <iostream> |
|
|
6 |
#include <strstream> |
7 |
+#include <cassert> |
8 |
#include <errno.h> |
9 |
#include <stdio.h> |
10 |
#include <unistd.h> |
11 |
@@ -178,11 +179,15 @@ |
12 |
|
13 |
// switch off non-blocking mode |
14 |
int fdFlags; |
15 |
- if ((fdFlags = fcntl(_fd, F_GETFL)) == -1) |
16 |
+ if ((fdFlags = fcntl(_fd, F_GETFL)) == -1) { |
17 |
+ close(_fd); |
18 |
throwModemException(_("getting file status flags failed")); |
19 |
+ } |
20 |
fdFlags &= ~O_NONBLOCK; |
21 |
- if (fcntl(_fd, F_SETFL, fdFlags) == -1) |
22 |
+ if (fcntl(_fd, F_SETFL, fdFlags) == -1) { |
23 |
+ close(_fd); |
24 |
throwModemException(_("switching of non-blocking mode failed")); |
25 |
+ } |
26 |
|
27 |
long int saveTimeoutVal = _timeoutVal; |
28 |
_timeoutVal = 3; |
29 |
@@ -194,17 +199,22 @@ |
30 |
|
31 |
// toggle DTR to reset modem |
32 |
int mctl = TIOCM_DTR; |
33 |
- if (ioctl(_fd, TIOCMBIC, &mctl) < 0) |
34 |
+ if (ioctl(_fd, TIOCMBIC, &mctl) < 0) { |
35 |
+ close(_fd); |
36 |
throwModemException(_("clearing DTR failed")); |
37 |
+ } |
38 |
// the waiting time for DTR toggling is increased with each loop |
39 |
usleep(holdoff[initTries]); |
40 |
- if (ioctl(_fd, TIOCMBIS, &mctl) < 0) |
41 |
+ if (ioctl(_fd, TIOCMBIS, &mctl) < 0) { |
42 |
+ close(_fd); |
43 |
throwModemException(_("setting DTR failed")); |
44 |
- |
45 |
+ } |
46 |
// get line modes |
47 |
- if (tcgetattr(_fd, &t) < 0) |
48 |
+ if (tcgetattr(_fd, &t) < 0) { |
49 |
+ close(_fd); |
50 |
throwModemException(stringPrintf(_("tcgetattr device '%s'"), |
51 |
device.c_str())); |
52 |
+ } |
53 |
|
54 |
// set line speed |
55 |
cfsetispeed(&t, lineSpeed); |
56 |
@@ -229,9 +239,11 @@ |
57 |
t.c_cc[VSUSP] = 0; |
58 |
|
59 |
// write back |
60 |
- if(tcsetattr (_fd, TCSANOW, &t) < 0) |
61 |
+ if(tcsetattr (_fd, TCSANOW, &t) < 0) { |
62 |
+ close(_fd); |
63 |
throwModemException(stringPrintf(_("tcsetattr device '%s'"), |
64 |
device.c_str())); |
65 |
+ } |
66 |
// the waiting time for writing to the ME/TA is increased with each loop |
67 |
usleep(holdoff[initTries]); |
68 |
|
69 |
@@ -279,11 +291,14 @@ |
70 |
catch (GsmException &e) |
71 |
{ |
72 |
_timeoutVal = saveTimeoutVal; |
73 |
- if (initTries == 0) |
74 |
+ if (initTries == 0) { |
75 |
+ close(_fd); |
76 |
throw e; |
77 |
+ } |
78 |
} |
79 |
} |
80 |
// no response after 3 tries |
81 |
+ close(_fd); |
82 |
throw GsmException(stringPrintf(_("reset modem failed '%s'"), |
83 |
device.c_str()), OtherError); |
84 |
} |