diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-12 09:57:22 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-07-12 09:57:22 +0000 |
commit | 257730a5f6ac68d21eaa4158d1747ee6cbd65391 (patch) | |
tree | 9a35ac1dd8861c4ebf00f5873dba8b5c87ad8080 | |
parent | 7542b63e25e6b11ced7d53a16bf8a724815a68a3 (diff) | |
download | gnunet-257730a5f6ac68d21eaa4158d1747ee6cbd65391.tar.gz gnunet-257730a5f6ac68d21eaa4158d1747ee6cbd65391.zip |
clean up
-rw-r--r-- | src/transport/plugin_transport_http.c | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index eae422cc9..887be99b8 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -331,7 +331,7 @@ struct Plugin | |||
331 | /** | 331 | /** |
332 | * The task sending data | 332 | * The task sending data |
333 | */ | 333 | */ |
334 | GNUNET_SCHEDULER_TaskIdentifier http_server_task_send; | 334 | GNUNET_SCHEDULER_TaskIdentifier http_curl_task; |
335 | 335 | ||
336 | /** | 336 | /** |
337 | * cURL Multihandle | 337 | * cURL Multihandle |
@@ -1147,9 +1147,9 @@ static size_t curl_receive_cb( void *stream, size_t size, size_t nmemb, void *pt | |||
1147 | * Function setting up file descriptors and scheduling task to run | 1147 | * Function setting up file descriptors and scheduling task to run |
1148 | * @param cls closure | 1148 | * @param cls closure |
1149 | * @param ses session to send data to | 1149 | * @param ses session to send data to |
1150 | * @return bytes sent to peer | 1150 | * @param |
1151 | */ | 1151 | */ |
1152 | static size_t send_schedule(void *cls, struct Session* ses ); | 1152 | static int curl_schedule(void *cls, struct Session* ses ); |
1153 | 1153 | ||
1154 | 1154 | ||
1155 | 1155 | ||
@@ -1158,12 +1158,11 @@ static size_t send_schedule(void *cls, struct Session* ses ); | |||
1158 | * @param cls plugin | 1158 | * @param cls plugin |
1159 | * @param ses session to send data to | 1159 | * @param ses session to send data to |
1160 | * @param con connection | 1160 | * @param con connection |
1161 | * @return bytes sent to peer | 1161 | * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok |
1162 | */ | 1162 | */ |
1163 | static ssize_t send_check_connections (void *cls, struct Session *ps) | 1163 | static ssize_t send_check_connections (void *cls, struct Session *ps) |
1164 | { | 1164 | { |
1165 | struct Plugin *plugin = cls; | 1165 | struct Plugin *plugin = cls; |
1166 | int bytes_sent = 0; | ||
1167 | CURLMcode mret; | 1166 | CURLMcode mret; |
1168 | struct HTTP_Message * msg; | 1167 | struct HTTP_Message * msg; |
1169 | struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; | 1168 | struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; |
@@ -1201,9 +1200,10 @@ static ssize_t send_check_connections (void *cls, struct Session *ps) | |||
1201 | _("%s failed at %s:%d: `%s'\n"), | 1200 | _("%s failed at %s:%d: `%s'\n"), |
1202 | "curl_multi_add_handle", __FILE__, __LINE__, | 1201 | "curl_multi_add_handle", __FILE__, __LINE__, |
1203 | curl_multi_strerror (mret)); | 1202 | curl_multi_strerror (mret)); |
1204 | return -1; | 1203 | return GNUNET_SYSERR; |
1205 | } | 1204 | } |
1206 | bytes_sent = send_schedule (plugin, NULL); | 1205 | if (curl_schedule (plugin, NULL) == GNUNET_SYSERR) |
1206 | return GNUNET_SYSERR; | ||
1207 | #if DEBUG_CONNECTIONS | 1207 | #if DEBUG_CONNECTIONS |
1208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",ps); | 1208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: inbound not connected, initiating connection\n",ps); |
1209 | #endif | 1209 | #endif |
@@ -1212,7 +1212,7 @@ static ssize_t send_check_connections (void *cls, struct Session *ps) | |||
1212 | 1212 | ||
1213 | /* waiting for receive direction */ | 1213 | /* waiting for receive direction */ |
1214 | if (ps->recv_connected==GNUNET_NO) | 1214 | if (ps->recv_connected==GNUNET_NO) |
1215 | return 0; | 1215 | return GNUNET_NO; |
1216 | 1216 | ||
1217 | /* SEND DIRECTION */ | 1217 | /* SEND DIRECTION */ |
1218 | /* Check if session is connected to send data, otherwise connect to peer */ | 1218 | /* Check if session is connected to send data, otherwise connect to peer */ |
@@ -1223,16 +1223,20 @@ static ssize_t send_check_connections (void *cls, struct Session *ps) | |||
1223 | #if DEBUG_CONNECTIONS | 1223 | #if DEBUG_CONNECTIONS |
1224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound active, enqueueing message\n",ps); | 1224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound active, enqueueing message\n",ps); |
1225 | #endif | 1225 | #endif |
1226 | return bytes_sent; | 1226 | return GNUNET_YES; |
1227 | } | 1227 | } |
1228 | if (ps->send_active == GNUNET_NO) | 1228 | if (ps->send_active == GNUNET_NO) |
1229 | { | 1229 | { |
1230 | #if DEBUG_CONNECTIONS | 1230 | #if DEBUG_CONNECTIONS |
1231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound paused, unpausing existing connection and enqueueing message\n",ps); | 1231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: outbound paused, unpausing existing connection and enqueueing message\n",ps); |
1232 | #endif | 1232 | #endif |
1233 | curl_easy_pause(ps->send_endpoint,CURLPAUSE_CONT); | 1233 | if (CURLE_OK == curl_easy_pause(ps->send_endpoint,CURLPAUSE_CONT)) |
1234 | ps->send_active=GNUNET_YES; | 1234 | { |
1235 | return bytes_sent; | 1235 | ps->send_active=GNUNET_YES; |
1236 | return GNUNET_YES; | ||
1237 | } | ||
1238 | else | ||
1239 | return GNUNET_SYSERR; | ||
1236 | } | 1240 | } |
1237 | } | 1241 | } |
1238 | /* not connected, initiate connection */ | 1242 | /* not connected, initiate connection */ |
@@ -1269,24 +1273,23 @@ static ssize_t send_check_connections (void *cls, struct Session *ps) | |||
1269 | _("%s failed at %s:%d: `%s'\n"), | 1273 | _("%s failed at %s:%d: `%s'\n"), |
1270 | "curl_multi_add_handle", __FILE__, __LINE__, | 1274 | "curl_multi_add_handle", __FILE__, __LINE__, |
1271 | curl_multi_strerror (mret)); | 1275 | curl_multi_strerror (mret)); |
1272 | return -1; | 1276 | return GNUNET_SYSERR; |
1273 | } | 1277 | } |
1274 | bytes_sent = send_schedule (plugin, NULL); | 1278 | if (curl_schedule (plugin, NULL) == GNUNET_SYSERR) |
1275 | return bytes_sent; | 1279 | return GNUNET_SYSERR; |
1280 | return GNUNET_YES; | ||
1276 | } | 1281 | } |
1277 | if (ps->direction == INBOUND) | 1282 | if (ps->direction == INBOUND) |
1278 | { | 1283 | { |
1279 | GNUNET_assert (NULL != ps->pending_msgs_tail); | 1284 | GNUNET_assert (NULL != ps->pending_msgs_tail); |
1280 | bytes_sent = 0; | ||
1281 | msg = ps->pending_msgs_tail; | 1285 | msg = ps->pending_msgs_tail; |
1282 | if ((ps->recv_connected==GNUNET_YES) && (ps->send_connected==GNUNET_YES)) | 1286 | if ((ps->recv_connected==GNUNET_YES) && (ps->send_connected==GNUNET_YES)) |
1283 | bytes_sent = msg->size; | 1287 | return GNUNET_YES; |
1284 | return bytes_sent; | ||
1285 | } | 1288 | } |
1286 | return 0; | 1289 | return GNUNET_SYSERR; |
1287 | } | 1290 | } |
1288 | 1291 | ||
1289 | static void send_execute (void *cls, | 1292 | static void curl_perform (void *cls, |
1290 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1293 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1291 | { | 1294 | { |
1292 | struct Plugin *plugin = cls; | 1295 | struct Plugin *plugin = cls; |
@@ -1300,7 +1303,8 @@ static void send_execute (void *cls, | |||
1300 | long http_result; | 1303 | long http_result; |
1301 | 1304 | ||
1302 | GNUNET_assert(cls !=NULL); | 1305 | GNUNET_assert(cls !=NULL); |
1303 | plugin->http_server_task_send = GNUNET_SCHEDULER_NO_TASK; | 1306 | |
1307 | plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; | ||
1304 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1308 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1305 | return; | 1309 | return; |
1306 | 1310 | ||
@@ -1432,16 +1436,16 @@ static void send_execute (void *cls, | |||
1432 | handles_last_run = running; | 1436 | handles_last_run = running; |
1433 | } | 1437 | } |
1434 | while (mret == CURLM_CALL_MULTI_PERFORM); | 1438 | while (mret == CURLM_CALL_MULTI_PERFORM); |
1435 | send_schedule(plugin, cls); | 1439 | curl_schedule(plugin, cls); |
1436 | } | 1440 | } |
1437 | 1441 | ||
1438 | 1442 | ||
1439 | /** | 1443 | /** |
1440 | * Function setting up file descriptors and scheduling task to run | 1444 | * Function setting up file descriptors and scheduling task to run |
1441 | * @param ses session to send data to | 1445 | * @param ses session to send data to |
1442 | * @return bytes sent to peer | 1446 | * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok |
1443 | */ | 1447 | */ |
1444 | static size_t send_schedule(void *cls, struct Session* ses ) | 1448 | static int curl_schedule(void *cls, struct Session* ses ) |
1445 | { | 1449 | { |
1446 | struct Plugin *plugin = cls; | 1450 | struct Plugin *plugin = cls; |
1447 | fd_set rs; | 1451 | fd_set rs; |
@@ -1465,7 +1469,7 @@ static size_t send_schedule(void *cls, struct Session* ses ) | |||
1465 | _("%s failed at %s:%d: `%s'\n"), | 1469 | _("%s failed at %s:%d: `%s'\n"), |
1466 | "curl_multi_fdset", __FILE__, __LINE__, | 1470 | "curl_multi_fdset", __FILE__, __LINE__, |
1467 | curl_multi_strerror (mret)); | 1471 | curl_multi_strerror (mret)); |
1468 | return -1; | 1472 | return GNUNET_SYSERR; |
1469 | } | 1473 | } |
1470 | mret = curl_multi_timeout (plugin->multi_handle, &to); | 1474 | mret = curl_multi_timeout (plugin->multi_handle, &to); |
1471 | if (mret != CURLM_OK) | 1475 | if (mret != CURLM_OK) |
@@ -1474,26 +1478,24 @@ static size_t send_schedule(void *cls, struct Session* ses ) | |||
1474 | _("%s failed at %s:%d: `%s'\n"), | 1478 | _("%s failed at %s:%d: `%s'\n"), |
1475 | "curl_multi_timeout", __FILE__, __LINE__, | 1479 | "curl_multi_timeout", __FILE__, __LINE__, |
1476 | curl_multi_strerror (mret)); | 1480 | curl_multi_strerror (mret)); |
1477 | return -1; | 1481 | return GNUNET_SYSERR; |
1478 | } | 1482 | } |
1479 | 1483 | ||
1480 | grs = GNUNET_NETWORK_fdset_create (); | 1484 | grs = GNUNET_NETWORK_fdset_create (); |
1481 | gws = GNUNET_NETWORK_fdset_create (); | 1485 | gws = GNUNET_NETWORK_fdset_create (); |
1482 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 1486 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
1483 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); | 1487 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); |
1484 | plugin->http_server_task_send = GNUNET_SCHEDULER_add_select (plugin->env->sched, | 1488 | plugin->http_curl_task = GNUNET_SCHEDULER_add_select (plugin->env->sched, |
1485 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1489 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1486 | GNUNET_SCHEDULER_NO_TASK, | 1490 | GNUNET_SCHEDULER_NO_TASK, |
1487 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), | 1491 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), |
1488 | grs, | 1492 | grs, |
1489 | gws, | 1493 | gws, |
1490 | &send_execute, | 1494 | &curl_perform, |
1491 | plugin); | 1495 | plugin); |
1492 | GNUNET_NETWORK_fdset_destroy (gws); | 1496 | GNUNET_NETWORK_fdset_destroy (gws); |
1493 | GNUNET_NETWORK_fdset_destroy (grs); | 1497 | GNUNET_NETWORK_fdset_destroy (grs); |
1494 | 1498 | return GNUNET_OK; | |
1495 | /* FIXME: return bytes REALLY sent */ | ||
1496 | return 0; | ||
1497 | } | 1499 | } |
1498 | 1500 | ||
1499 | 1501 | ||
@@ -1682,7 +1684,10 @@ http_plugin_send (void *cls, | |||
1682 | memcpy (msg->buf,msgbuf, msgbuf_size); | 1684 | memcpy (msg->buf,msgbuf, msgbuf_size); |
1683 | GNUNET_CONTAINER_DLL_insert(ps->pending_msgs_head,ps->pending_msgs_tail,msg); | 1685 | GNUNET_CONTAINER_DLL_insert(ps->pending_msgs_head,ps->pending_msgs_tail,msg); |
1684 | 1686 | ||
1685 | return send_check_connections (plugin, ps); | 1687 | if (send_check_connections (plugin, ps) != GNUNET_SYSERR) |
1688 | return msg->size; | ||
1689 | else | ||
1690 | return GNUNET_SYSERR; | ||
1686 | } | 1691 | } |
1687 | 1692 | ||
1688 | 1693 | ||
@@ -2062,10 +2067,10 @@ libgnunet_plugin_transport_http_done (void *cls) | |||
2062 | plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 2067 | plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
2063 | } | 2068 | } |
2064 | 2069 | ||
2065 | if ( plugin->http_server_task_send != GNUNET_SCHEDULER_NO_TASK) | 2070 | if ( plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) |
2066 | { | 2071 | { |
2067 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_server_task_send); | 2072 | GNUNET_SCHEDULER_cancel(plugin->env->sched, plugin->http_curl_task); |
2068 | plugin->http_server_task_send = GNUNET_SCHEDULER_NO_TASK; | 2073 | plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; |
2069 | } | 2074 | } |
2070 | 2075 | ||
2071 | /* free all peer information */ | 2076 | /* free all peer information */ |