Thanks for the code.
I patched it last night and it seems to be running normally. I don't
know if it's solved the problem yet. It will be a few days running
before I will be sure that there haven't been any problems.
I've attached a diff for anyone else that wants to backport this code
into 1.2.1.
Thanks again,
--
Mike Nugent
System Administrator
Calltrex
On Mon, 2003-11-17 at 18:54, Yulianto Z wrote:
> I jz look into 1.2.1 version. And it has exact code that running into my
> last bug (buffer bug). If you want to keep using 1.2.1 you could try to
> modify gw/smsc/smsc_at2.c. Replace 3 functions in that files (Below, I
> copy&paste those 3 functions from cvs-version..), and recompile them.
--- smsc_at2.orig.c 2003-11-18 10:57:03.000000000 -0800
+++ smsc_at2.c 2003-11-19 10:09:06.000000000 -0800
@@ -235,7 +235,7 @@
{
int count;
int s = 0;
- int write_count = 0;
+ int write_count = 0, data_written = 0;
Octstr *linestr = NULL;
linestr = octstr_format("%s\r", line);
@@ -243,19 +243,24 @@
debug("bb.smsc.at2", 0, "AT2[%s]: --> %s^M", octstr_get_cstr(privdata->name), line);
count = octstr_len(linestr);
- while (1) {
- errno = 0;
- s = write(privdata->fd, octstr_get_cstr(linestr), count);
- if (s < 0 && errno == EAGAIN && write_count < RETRY_SEND) {
- gwthread_sleep(1);
- ++write_count;
- } else
- break;
+ while (count > data_written) {
+ errno = 0;
+ s = write(privdata->fd, octstr_get_cstr(linestr) + data_written, count- data_written);
+ if (s < 0 && errno == EAGAIN && write_count < RETRY_SEND) {
+ gwthread_sleep(1);
+ ++write_count;
+ } else if (s > 0) {
+ data_written += s;
+ write_count = 0;
+ } else
+ break;
};
+
O_DESTROY(linestr);
if (s < 0) {
debug("bb.smsc.at2", 0, "AT2[%s]: write failed with errno %d",
octstr_get_cstr(privdata->name), errno);
+ tcflush(privdata->fd, TCOFLUSH);
return s;
}
tcdrain(privdata->fd);
@@ -284,27 +289,41 @@
if (s < 0) {
debug("bb.smsc.at2", 0, "AT2[%s]: write failed with errno %d",
octstr_get_cstr(privdata->name), errno);
+ tcflush(privdata->fd, TCOFLUSH);
return s;
}
tcdrain(privdata->fd);
- gwthread_sleep((double) privdata->modem->sendline_sleep / 1000);
+ gwthread_sleep((double) (privdata->modem == NULL ?
+ 100 : privdata->modem->sendline_sleep) / 1000);
return s;
}
int at2_write(PrivAT2data *privdata, char *line)
{
- int count;
+ int count, data_written = 0, write_count = 0;
int s;
count = strlen(line);
debug("bb.smsc.at2", 0, "AT2[%s]: --> %s", octstr_get_cstr(privdata->name), line);
- s = write(privdata->fd, line, count);
+
+ while(count > data_written) {
+ s = write(privdata->fd, line + data_written, count -data_written);
+ if (s < 0 && errno == EAGAIN && write_count < RETRY_SEND) {
+ gwthread_sleep(1);
+ ++write_count;
+ } else if (s > 0) {
+ data_written += s;
+ write_count = 0;
+ } else
+ break;
+ }
tcdrain(privdata->fd);
+ gwthread_sleep((double) (privdata->modem == NULL ?
+ 100 : privdata->modem->sendline_sleep) / 1000);
return s;
}
-
void at2_flush_buffer(PrivAT2data *privdata)
{
at2_read_buffer(privdata);