summaryrefslogtreecommitdiffstats
path: root/gisi
diff options
context:
space:
mode:
authorMika Liljeberg <mika.liljeberg@nokia.com>2010-10-06 11:17:56 +0300
committerAki Niemi <aki.niemi@nokia.com>2010-10-21 21:39:41 +0300
commit69fbe74276fb045af4f42b5168d5b8c77ba880d3 (patch)
tree96d845bf7966aa08080da7588f659e2dbfc5dc4d /gisi
parent64624500596ec4150dcd422ac7ba9cc9958a529d (diff)
downloadofono-69fbe74276fb045af4f42b5168d5b8c77ba880d3.tar.bz2
gisi: make timeout optional
Diffstat (limited to 'gisi')
-rw-r--r--gisi/client.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/gisi/client.c b/gisi/client.c
index f11594bd..2d7ced76 100644
--- a/gisi/client.c
+++ b/gisi/client.c
@@ -462,9 +462,10 @@ GIsiRequest *g_isi_vsendto(GIsiClient *client,
};
ssize_t ret;
size_t i, len;
+ unsigned int key;
uint8_t id;
- GIsiRequest *req;
+ GIsiRequest *req = NULL;
GIsiRequest **old;
if (!client) {
@@ -472,25 +473,33 @@ GIsiRequest *g_isi_vsendto(GIsiClient *client,
return NULL;
}
- req = g_try_new0(GIsiRequest, 1);
- if (!req) {
- errno = ENOMEM;
- return NULL;
- }
+ key = 1 + ((client->reqs.last + 1) % 255);
- req->client = client;
- req->id = (client->reqs.last + 1) % 255;
- req->func = cb;
- req->data = opaque;
- req->notify = notify;
+ if (cb) {
+ req = g_try_new0(GIsiRequest, 1);
+ if (!req) {
+ errno = ENOMEM;
+ return NULL;
+ }
- old = tsearch(req, &client->reqs.pending, g_isi_cmp);
- if (!old) {
- errno = ENOMEM;
- goto error;
- }
+ req->client = client;
+ req->id = key;
+ req->func = cb;
+ req->data = opaque;
+ req->notify = notify;
+
+ old = tsearch(req, &client->reqs.pending, g_isi_cmp);
+ if (!old) {
+ errno = ENOMEM;
+ goto error;
+ }
+ if (*old == req)
+ old = NULL;
+
+ } else
+ old = tfind(&key, &client->reqs.pending, g_isi_cmp);
- if (*old != req) {
+ if (old) {
/* FIXME: perhaps retry with randomized access after
* initial miss. Although if the rate at which
* requests are sent is so high that the transaction
@@ -500,7 +509,7 @@ GIsiRequest *g_isi_vsendto(GIsiClient *client,
goto error;
}
- id = req->id;
+ id = key;
_iov[0].iov_base = &id;
_iov[0].iov_len = 1;
@@ -522,8 +531,10 @@ GIsiRequest *g_isi_vsendto(GIsiClient *client,
goto error;
}
- req->timeout = g_timeout_add_seconds(timeout, g_isi_timeout, req);
- client->reqs.last = req->id;
+ if (req && timeout)
+ req->timeout = g_timeout_add_seconds(timeout, g_isi_timeout,
+ req);
+ client->reqs.last = key;
return req;
error: