summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/opentracker.c9
-rw-r--r--src/ot_tcp.c12
-rw-r--r--src/ot_workqueue.c35
-rw-r--r--src/ot_workqueue.h2
4 files changed, 41 insertions, 17 deletions
diff --git a/src/opentracker.c b/src/opentracker.c
index 759a6d0..36dff71 100644
--- a/src/opentracker.c
+++ b/src/opentracker.c
@@ -25,6 +25,7 @@
25#include "ot_config.h" 25#include "ot_config.h"
26#include "ot_hex.h" 26#include "ot_hex.h"
27#include "ot_http.h" 27#include "ot_http.h"
28#include "ot_iovec.h"
28#include "ot_ip.h" 29#include "ot_ip.h"
29#include "ot_livesync.h" 30#include "ot_livesync.h"
30#include "ot_mutex.h" 31#include "ot_mutex.h"
@@ -107,6 +108,7 @@ static void *server_mainloop(void *args) {
107 struct iovec *iovector; 108 struct iovec *iovector;
108 size_t iovec_entries; 109 size_t iovec_entries;
109 int is_partial; 110 int is_partial;
111 uint32_t generation;
110 112
111 (void)args; 113 (void)args;
112 114
@@ -149,8 +151,13 @@ static void *server_mainloop(void *args) {
149 } 151 }
150 } 152 }
151 153
152 while ((sock = workqueue_popresult(&iovec_entries, &iovector, &is_partial)) != -1) 154 while ((sock = workqueue_popresult(&iovec_entries, &iovector, &is_partial, &generation)) != -1) {
155 if (fdstate_generation((int)sock) != generation) {
156 iovec_free(&iovec_entries, &iovector);
157 continue;
158 }
153 http_sendiovecdata(sock, &ws, iovec_entries, iovector, is_partial); 159 http_sendiovecdata(sock, &ws, iovec_entries, iovector, is_partial);
160 }
154 161
155 if (time_is_past(next_timeout_check)) { 162 if (time_is_past(next_timeout_check)) {
156 int cursor = 0; 163 int cursor = 0;
diff --git a/src/ot_tcp.c b/src/ot_tcp.c
index 5d7b78f..67a0ebc 100644
--- a/src/ot_tcp.c
+++ b/src/ot_tcp.c
@@ -44,9 +44,19 @@ static ssize_t header_complete(char *request, ssize_t byte_count) {
44 44
45void tcp_read(const int64_t sock, struct ot_workstruct *ws) { 45void tcp_read(const int64_t sock, struct ot_workstruct *ws) {
46 struct http_data *cookie = fdstate_cookie(sock); 46 struct http_data *cookie = fdstate_cookie(sock);
47 ssize_t byte_count = read((int)sock, ws->inbuf, G_INBUF_SIZE); 47 ssize_t byte_count;
48 uint32_t generation; 48 uint32_t generation;
49 49
50 /* We're not supposed to read from a socket that waits for
51 our answer. Prevent its reply from being sent to the next
52 generation on that fd. */
53 if (cookie->flag & (STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER)) {
54 http_close(sock);
55 return;
56 }
57
58 byte_count = read((int)sock, ws->inbuf, G_INBUF_SIZE);
59
50 if (byte_count == 0 || (byte_count == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)) { 60 if (byte_count == 0 || (byte_count == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)) {
51 http_close(sock); 61 http_close(sock);
52 return; 62 return;
diff --git a/src/ot_workqueue.c b/src/ot_workqueue.c
index 56a7cd2..cdefddc 100644
--- a/src/ot_workqueue.c
+++ b/src/ot_workqueue.c
@@ -9,6 +9,7 @@
9#include <unistd.h> 9#include <unistd.h>
10 10
11/* Opentracker */ 11/* Opentracker */
12#include "ot_fdstate.h"
12#include "ot_iovec.h" 13#include "ot_iovec.h"
13#include "ot_workqueue.h" 14#include "ot_workqueue.h"
14#include "trackerlogic.h" 15#include "trackerlogic.h"
@@ -20,6 +21,7 @@ struct ot_task {
20 ot_taskid taskid; 21 ot_taskid taskid;
21 ot_tasktype tasktype; 22 ot_tasktype tasktype;
22 int64_t sock; 23 int64_t sock;
24 uint32_t generation;
23 size_t iovec_entries; 25 size_t iovec_entries;
24 struct iovec *iovec; 26 struct iovec *iovec;
25 struct ot_task *next; 27 struct ot_task *next;
@@ -40,6 +42,7 @@ int workqueue_pushtask(int64_t sock, ot_tasktype tasktype) {
40 task->taskid = 0; 42 task->taskid = 0;
41 task->tasktype = tasktype; 43 task->tasktype = tasktype;
42 task->sock = sock; 44 task->sock = sock;
45 task->generation = fdstate_generation((int)sock);
43 task->iovec_entries = 0; 46 task->iovec_entries = 0;
44 task->iovec = NULL; 47 task->iovec = NULL;
45 task->next = 0; 48 task->next = 0;
@@ -65,22 +68,25 @@ void workqueue_canceltask(int64_t sock) {
65 /* Want exclusive access to tasklist */ 68 /* Want exclusive access to tasklist */
66 pthread_mutex_lock(&tasklist_mutex); 69 pthread_mutex_lock(&tasklist_mutex);
67 70
68 for (task = &tasklist; *task; task = &((*task)->next)) 71 task = &tasklist;
69 if ((*task)->sock == sock) { 72 while (*task) {
70 struct iovec *iovec = (*task)->iovec; 73 struct ot_task *ptask = *task;
71 struct ot_task *ptask = *task; 74 size_t i;
72 size_t i;
73
74 /* Free task's iovec, the buffers it points at and the vector itself */
75 for (i = 0; i < (*task)->iovec_entries; ++i)
76 free(iovec[i].iov_base);
77 free(iovec);
78 75
79 *task = (*task)->next; 76 if (ptask->sock != sock) {
80 free(ptask); 77 task = &ptask->next;
81 break; 78 continue;
82 } 79 }
83 80
81 /* Free task's iovec, the buffers it points at and the vector itself */
82 for (i = 0; i < ptask->iovec_entries; ++i)
83 free(ptask->iovec[i].iov_base);
84 free(ptask->iovec);
85
86 *task = ptask->next;
87 free(ptask);
88 }
89
84 /* Release lock */ 90 /* Release lock */
85 pthread_mutex_unlock(&tasklist_mutex); 91 pthread_mutex_unlock(&tasklist_mutex);
86} 92}
@@ -190,7 +196,7 @@ int workqueue_pushchunked(ot_taskid taskid, struct iovec *iovec) {
190 return task ? 0 : -1; 196 return task ? 0 : -1;
191} 197}
192 198
193int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is_partial) { 199int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is_partial, uint32_t *generation) {
194 struct ot_task **task; 200 struct ot_task **task;
195 int64_t sock = -1; 201 int64_t sock = -1;
196 202
@@ -205,6 +211,7 @@ int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is
205 *iovec_entries = ptask->iovec_entries; 211 *iovec_entries = ptask->iovec_entries;
206 *iovec = ptask->iovec; 212 *iovec = ptask->iovec;
207 sock = ptask->sock; 213 sock = ptask->sock;
214 *generation = ptask->generation;
208 215
209 if ((*task)->tasktype == TASK_DONE) { 216 if ((*task)->tasktype == TASK_DONE) {
210 *task = ptask->next; 217 *task = ptask->next;
diff --git a/src/ot_workqueue.h b/src/ot_workqueue.h
index d8f30d6..982292e 100644
--- a/src/ot_workqueue.h
+++ b/src/ot_workqueue.h
@@ -64,7 +64,7 @@ void workqueue_pushsuccess(ot_taskid taskid);
64ot_taskid workqueue_poptask(ot_tasktype *tasktype); 64ot_taskid workqueue_poptask(ot_tasktype *tasktype);
65int workqueue_pushresult(ot_taskid taskid, size_t iovec_entries, struct iovec *iovector); 65int workqueue_pushresult(ot_taskid taskid, size_t iovec_entries, struct iovec *iovector);
66int workqueue_pushchunked(ot_taskid taskid, struct iovec *iovec); 66int workqueue_pushchunked(ot_taskid taskid, struct iovec *iovec);
67int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovector, int *is_partial); 67int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovector, int *is_partial, uint32_t *generation);
68 68
69void workqueue_init(void); 69void workqueue_init(void);
70void workqueue_deinit(void); 70void workqueue_deinit(void);