• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂503 (tree)
時間2012-06-23 14:44:14
作者ornse01

Log Message

fix style for semaphore coding.

Change Summary

差異

--- bchanf/trunk/src/http/http_connector.c (revision 502)
+++ bchanf/trunk/src/http/http_connector.c (revision 503)
@@ -308,6 +308,19 @@
308308 ID sem;
309309 };
310310
311+#define HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector) \
312+ err = wai_sem((connector)->sem, T_FOREVER); \
313+ if (err < 0) { \
314+ return err; \
315+ }
316+#define HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_VOID(connector) \
317+ err = wai_sem((connector)->sem, T_FOREVER); \
318+ if (err < 0) { \
319+ return; \
320+ }
321+#define HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector) \
322+ sig_sem((connector)->sem);
323+
311324 #define HTTP_CONNECTOR_FLAG_CREARMASK(flag) (~(flag))
312325 #define HTTP_CONNECTOR_FLAG_REQUEST 0x00000001
313326 #define HTTP_CONNECTOR_FLAG_EVENT 0x00000002
@@ -319,12 +332,9 @@
319332 ID id;
320333 W err;
321334
322- err = wai_sem(connector->sem, T_FOREVER);
323- if (err < 0) {
324- return err;
325- }
335+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
326336 id = http_reqdict_allocate(connector->dict, host, host_len, port, method);
327- sig_sem(connector->sem);
337+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
328338 if (id < 0) {
329339 DP_ER("http_reqdict_allocate", id);
330340 return id; /* TODO */
@@ -346,14 +356,11 @@
346356 Bool transport_close = True;
347357 W err;
348358
349- err = wai_sem(connector->sem, T_FOREVER);
350- if (err < 0) {
351- return;
352- }
359+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_VOID(connector);
353360
354361 entry = http_reqdict_getentrybyID(connector->dict, endpoint);
355362 if (entry == NULL) {
356- sig_sem(connector->sem);
363+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
357364 return;
358365 }
359366
@@ -376,7 +383,7 @@
376383
377384 http_reqdict_free(connector->dict, endpoint);
378385
379- sig_sem(connector->sem);
386+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
380387 }
381388
382389 LOCAL W http_connector_searchwaiting(http_connector_t *connector)
@@ -461,13 +468,15 @@
461468 W err;
462469 Bool evt = False;
463470
464- err = wai_sem(connector->sem, tmout);
471+ err = wai_flg(connector->flg, HTTP_CONNECTOR_FLAG_REQUEST, WF_AND, tmout);
465472 if (err < 0) {
466- return err;
473+ return 0;
467474 }
475+
476+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
468477 err = http_connector_searchwaiting(connector);
469478 if (err < 0) {
470- sig_sem(connector->sem);
479+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
471480 return err;
472481 }
473482 if (err > 0) {
@@ -476,7 +485,7 @@
476485 http_transport_releaseunusedendpoint(connector->transport);
477486
478487 err = http_connector_waitreceiving(connector, tmout);
479- sig_sem(connector->sem);
488+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
480489 if (err < 0) {
481490 return err;
482491 }
@@ -797,12 +806,9 @@
797806 DP_ER("wai_flg", err);
798807 return err;
799808 }
800- err = wai_sem(connector->sem, T_FOREVER);
801- if (err < 0) {
802- return err;
803- }
809+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
804810 found = http_connector_searcheventtarget(connector, event);
805- sig_sem(connector->sem);
811+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
806812 if (found == False) {
807813 err = clr_flg(connector->flg, HTTP_CONNECTOR_FLAG_CLEARMASK_EVENT);
808814 if (err < 0) {
@@ -849,16 +855,13 @@
849855 Bool cont;
850856 CONST UB *str;
851857
852- err = wai_sem(connector->sem, T_FOREVER);
853- if (err < 0) {
854- return err;
855- }
858+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
856859
857860 HTTP_CONNECTOR_SENDXXX_GET_CHECK(connector, endpoint, SEND_REQUEST_LINE, entry);
858861
859862 err = http_requestlinestream_initialize(&reqline, entry->method, path, path_len);
860863 if (err < 0) {
861- sig_sem(connector->sem);
864+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
862865 return err;
863866 }
864867 for (;;) {
@@ -874,13 +877,13 @@
874877 http_requestlinestream_finalize(&reqline);
875878
876879 if (err < 0) {
877- sig_sem(connector->sem);
880+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
878881 return err;
879882 }
880883
881884 entry->snd_state = SEND_HEADER_MINE;
882885
883- sig_sem(connector->sem);
886+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
884887
885888 return 0;
886889 }
@@ -913,10 +916,7 @@
913916 http_reqentry_t *entry;
914917 W err;
915918
916- err = wai_sem(connector->sem, T_FOREVER);
917- if (err < 0) {
918- return err;
919- }
919+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
920920
921921 HTTP_CONNECTOR_SENDXXX_GET_CHECK_2(connector, endpoint, SEND_HEADER_MINE, SEND_HEADER_USER, entry);
922922
@@ -923,13 +923,13 @@
923923 if (entry->snd_state == SEND_HEADER_MINE) {
924924 err = http_connector_writedefaultheader(connector, entry->transport, entry->host, entry->host_len);
925925 if (err < 0) {
926- sig_sem(connector->sem);
926+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
927927 return err;
928928 }
929929 entry->snd_state = SEND_HEADER_USER;
930930 }
931931
932- sig_sem(connector->sem);
932+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
933933
934934 return 0;
935935 }
@@ -939,10 +939,7 @@
939939 http_reqentry_t *entry;
940940 W err;
941941
942- err = wai_sem(connector->sem, T_FOREVER);
943- if (err < 0) {
944- return err;
945- }
942+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
946943
947944 HTTP_CONNECTOR_SENDXXX_GET_CHECK_2(connector, endpoint, SEND_HEADER_MINE, SEND_HEADER_USER, entry);
948945
@@ -949,19 +946,19 @@
949946 if (entry->snd_state == SEND_HEADER_MINE) {
950947 err = http_connector_writedefaultheader(connector, entry->transport, entry->host, entry->host_len);
951948 if (err < 0) {
952- sig_sem(connector->sem);
949+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
953950 return err;
954951 }
955952 }
956953 err = http_transport_write(connector->transport, entry->transport, "\r\n", 2);
957954 if (err < 0) {
958- sig_sem(connector->sem);
955+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
959956 return err;
960957 }
961958
962959 entry->snd_state = SEND_MESSAGE_BODY;
963960
964- sig_sem(connector->sem);
961+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
965962
966963 return 0;
967964 }
@@ -971,15 +968,12 @@
971968 http_reqentry_t *entry;
972969 W err;
973970
974- err = wai_sem(connector->sem, T_FOREVER);
975- if (err < 0) {
976- return err;
977- }
971+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
978972
979973 HTTP_CONNECTOR_SENDXXX_GET_CHECK(connector, endpoint, SEND_MESSAGE_BODY, entry);
980974
981975 err = http_transport_write(connector->transport, entry->transport, p, len);
982- sig_sem(connector->sem);
976+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
983977 if (err < 0) {
984978 return err;
985979 }
@@ -992,16 +986,13 @@
992986 http_reqentry_t *entry;
993987 W err;
994988
995- err = wai_sem(connector->sem, T_FOREVER);
996- if (err < 0) {
997- return err;
998- }
989+ HTTP_CONNECTOR_ENTER_CRITICAL_SECTION_RET_ERR(connector);
999990
1000991 HTTP_CONNECTOR_SENDXXX_GET_CHECK(connector, endpoint, SEND_MESSAGE_BODY, entry);
1001992
1002993 entry->status = WAITING_RESPONSE;
1003994
1004- sig_sem(connector->sem);
995+ HTTP_CONNECTOR_LEAVE_CRITICAL_SECTION(connector);
1005996
1006997 return 0;
1007998 }
Show on old repository browser