• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionb4dc0c921ee782d841bc476470f28605529c03c2 (tree)
Zeit2014-12-24 16:07:22
AutorHiroaki Nakano <nakano.hiroaki@nttc...>
CommiterHiroaki Nakano

Log Message

2014/12/24 edit

Signed-off-by: Hiroaki Nakano <nakano.hiroaki@nttcom.co.jp>

Ändern Zusammenfassung

Diff

--- a/include/l7vs_lsock.h
+++ b/include/l7vs_lsock.h
@@ -50,6 +50,7 @@ struct l7vs_dest;
5050 extern int l7vs_lsock_init();
5151 extern void l7vs_lsock_fini();
5252 extern struct l7vs_lsock* l7vs_lsock_get( struct sockaddr_in*, uint8_t, int );
53+extern struct l7vs_lsock* l7vs_lsock_get_dummy( struct sockaddr_in*, uint8_t, int );
5354 extern void l7vs_lsock_put( struct l7vs_lsock* );
5455 extern struct l7vs_lsock* l7vs_lsock_table_lookup( struct sockaddr_in*, uint8_t );
5556 extern void l7vs_lsock_add_service( struct l7vs_lsock*, struct l7vs_service* );
--- a/src/lsock.c
+++ b/src/lsock.c
@@ -261,6 +261,92 @@ l7vs_lsock_get(struct sockaddr_in *sin, uint8_t proto, int backlog)
261261 }
262262
263263 /*!
264+ * look up infomation for socket
265+ * return lsock structure without socket and iomux.
266+ *
267+ * @param[in] sin socket address struct( if ipv6 may be change this struct )
268+ * @param[in] proto TCS/UDP select.
269+ * @param[in] backlog
270+ */
271+struct l7vs_lsock *
272+l7vs_lsock_get_dummy(struct sockaddr_in *sin, uint8_t proto, int backlog)
273+{
274+ struct l7vs_lsock *lsock;
275+ int stype;
276+ int ret;
277+ int on = 1;
278+
279+ if (logger_get_log_level(LOG_CAT_L7VSD_SYSTEM_SOCKET) == LOG_LV_DEBUG) {
280+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_SYSTEM_SOCKET,20,
281+ "in_fuction: struct l7vs_lsock * l7vs_lsock_get_dummy(struct sockaddr_in *sin, uint8_t proto, int backlog)"
282+ "*sin =%p :proto = %d :backlog = %d :",
283+ sin,proto,backlog);
284+ }
285+
286+ if (sin == NULL) {
287+ return NULL;
288+ }
289+
290+ lsock = l7vs_lsock_table_lookup(sin, proto);
291+ if (lsock != NULL) {
292+ lsock->refcnt++;
293+ if (logger_get_log_level(LOG_CAT_L7VSD_SYSTEM_SOCKET) == LOG_LV_DEBUG) {
294+ char lsock_str[DEBUG_STR_LEN] = {0};
295+ l7vs_lsock_c_str(lsock_str, lsock);
296+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_SYSTEM_SOCKET,21,
297+ "table look up: lsock=%s", lsock_str);
298+ }
299+ return lsock;
300+ }
301+
302+ switch (proto) {
303+ case IPPROTO_TCP:
304+ stype = SOCK_STREAM;
305+ break;
306+ case IPPROTO_UDP:
307+ stype = SOCK_DGRAM;
308+ break;
309+ default:
310+ LOGGER_PUT_LOG_ERROR(LOG_CAT_L7VSD_SYSTEM_SOCKET,21,
311+ "Protocol number should be TCP or UDP (%d)", proto);
312+ return NULL;
313+ }
314+
315+ lsock = (struct l7vs_lsock *)calloc(1, sizeof(*lsock));
316+ if (lsock == NULL) {
317+ LOGGER_PUT_LOG_ERROR(LOG_CAT_L7VSD_SYSTEM_MEMORY,14, "Could not allocate lsock");
318+ return lsock;
319+ }
320+ if (logger_get_log_level(LOG_CAT_L7VSD_SYSTEM_MEMORY) == LOG_LV_DEBUG) {
321+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_SYSTEM_MEMORY,6,
322+ "in function l7vs_lsock_get: allocate memory"
323+ " : size=%zu ,pointer=%p", sizeof(*lsock),lsock);
324+ }
325+
326+ if (logger_get_log_level(LOG_CAT_L7VSD_SYSTEM_SOCKET) == LOG_LV_DEBUG) {
327+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_SYSTEM_SOCKET,22, "creating lsock %p", lsock);
328+ }
329+ lsock->proto = proto;
330+
331+ lsock->addr = *sin;
332+
333+ lsock->refcnt = 1;
334+ lsock->fast_schedule = 1;
335+
336+ l7vs_lsock_table_add(lsock); //Add socket in the list. It may be used for maintaining session (Am not sure)
337+// l7vs_iomux_add(&lsock->iom, L7VS_IOMUX_READ);
338+
339+ if (logger_get_log_level(LOG_CAT_L7VSD_SYSTEM_SOCKET) == LOG_LV_DEBUG) {
340+ char lsock_str[DEBUG_STR_LEN] = {0};
341+ l7vs_lsock_c_str(lsock_str, lsock);
342+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_SYSTEM_SOCKET,23,
343+ "creat: lsock=%s", lsock_str);
344+ }
345+
346+ return lsock;
347+}
348+
349+/*!
264350 * lisning socket remove list and iomuxlist.
265351 * @param[in] lsock removing lisning socket
266352 * @return void
--- a/src/service.c
+++ b/src/service.c
@@ -625,19 +625,23 @@ l7vs_service_list_dest_arg(struct l7vs_service *srv,
625625 * @return int number currently created / -1 failure
626626 */
627627 static l7vs_service *
628-make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err)
628+make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err, pid_t pid)
629629 {
630630 int ret;
631631
632- struct l7vs_protomod *pmod;
633- struct l7vs_scheduler *sched;
634- struct l7vs_service *srv;
635- struct l7vs_lsock *lsock;
636- struct l7vs_dest *sorry_dest; //! sorry-server destination
632+ struct l7vs_protomod *pmod;
633+ struct l7vs_scheduler *sched;
634+ struct l7vs_service *srv;
635+ struct l7vs_lsock *lsock;
636+ struct l7vs_dest *sorry_dest; //! sorry-server destination
637637 // struct l7vs_service_repdata * service_replicationdata;
638638
639639 /* ソケット作成 */
640- lsock = l7vs_lsock_get(&arg->srv_arg.addr, arg->srv_arg.proto, arg->srv_arg.backlog);
640+ if(pid == 0)
641+ lsock = l7vs_lsock_get(&arg->srv_arg.addr, arg->srv_arg.proto, arg->srv_arg.backlog);
642+ else
643+ lsock = l7vs_lsock_get_dummy(&arg->srv_arg.addr, arg->srv_arg.proto, arg->srv_arg.backlog);
644+
641645 if(lsock == NULL) {
642646 LOGGER_PUT_LOG_ERROR( LOG_CAT_L7VSD_VIRTUAL_SERVICE,1, "Could not create listen socket" );
643647 *err = L7VS_CONFIG_ERR_NOSOCK;
@@ -654,7 +658,7 @@ make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err)
654658 /* プロトコルモジュールロード */
655659 pmod = l7vs_protomod_get(arg->srv_arg.protomod);
656660 if (pmod == NULL) {
657- l7vs_lsock_put(lsock);
661+ if(pid==0) l7vs_lsock_put(lsock);
658662 *err = L7VS_CONFIG_ERR_NOMEM;
659663 //debug output
660664 if( LOG_LV_DEBUG == logger_get_log_level( LOG_CAT_L7VSD_VIRTUAL_SERVICE ) ){
@@ -670,7 +674,7 @@ make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err)
670674 sched = l7vs_sched_get(arg->srv_arg.schedmod);
671675 if (sched == NULL) {
672676 l7vs_protomod_put(pmod);
673- l7vs_lsock_put(lsock);
677+ if(pid==0) l7vs_lsock_put(lsock);
674678 *err = L7VS_CONFIG_ERR_NOSCHED;
675679 //debug output
676680 if( LOG_LV_DEBUG == logger_get_log_level( LOG_CAT_L7VSD_VIRTUAL_SERVICE ) ){
@@ -688,7 +692,7 @@ make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err)
688692 if (sorry_dest == NULL) {
689693 l7vs_sched_put(sched);
690694 l7vs_protomod_put(pmod);
691- l7vs_lsock_put(lsock);
695+ if(pid==0) l7vs_lsock_put(lsock);
692696 *err = L7VS_CONFIG_ERR_NOMEM;
693697 //debug output
694698 if( LOG_LV_DEBUG == logger_get_log_level( LOG_CAT_L7VSD_VIRTUAL_SERVICE ) ){
@@ -706,7 +710,7 @@ make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err)
706710 l7vs_dest_destroy(sorry_dest);
707711 l7vs_sched_put(sched);
708712 l7vs_protomod_put(pmod);
709- l7vs_lsock_put(lsock);
713+ if(pid==0) l7vs_lsock_put(lsock);
710714 *err = L7VS_CONFIG_ERR_NOMEM;
711715 LOGGER_PUT_LOG_ERROR( LOG_CAT_L7VSD_SYSTEM_MEMORY,5, "l7vs_service memory allocate error" );
712716 return NULL;
@@ -736,7 +740,7 @@ make_l7vs_service_data( l7vs_service_arg_multi *arg, int *err)
736740 l7vs_dest_destroy(sorry_dest);
737741 l7vs_sched_put(sched);
738742 l7vs_protomod_put(pmod);
739- l7vs_lsock_put(lsock);
743+ if(pid==0) l7vs_lsock_put(lsock);
740744 *err = L7VS_CONFIG_ERR_NOMEM;
741745 //debug output
742746 if( LOG_LV_DEBUG == logger_get_log_level( LOG_CAT_L7VSD_VIRTUAL_SERVICE ) ){
@@ -974,7 +978,7 @@ l7vs_notify_proto_of_child(gpointer pid,struct l7vs_service_arg_multi *arg)
974978 /*!
975979 * check child process when create service. and send information for adding service.
976980 * @param[in] *arg l7vs_service_arg_multi
977- * @return 0: nothing IP+port, 1: exist IP+port
981+ * @return 0: nothing IP+port, 1: exist IP+port, -1: error
978982 */
979983 int
980984 l7vs_child_process_check(struct l7vs_service_arg_multi *arg)
@@ -1000,12 +1004,14 @@ l7vs_child_process_check(struct l7vs_service_arg_multi *arg)
10001004 if(ret){
10011005 /* あったのでサービス重複エラー */
10021006 LOGGER_PUT_LOG_ERROR( LOG_CAT_L7VSD_VIRTUAL_SERVICE,2, "Virtual service already exists" );
1007+ srv_sock_check_flg = -1;
10031008 }else{
10041009 /* 親持ちのリストl7vs_child_proto_grpにプロトコル追加 */
10051010 l7vs_child_proto_add_proto(cpgrp,arg->srv_arg.protomod);
10061011
10071012 /* 既存子プロセス持ちのリストにprotocol追加通知 */
10081013 g_slist_foreach(cpgrp->child_pid,(GFunc)l7vs_notify_proto_of_child,arg);
1014+
10091015 }
10101016 }
10111017
@@ -1018,7 +1024,7 @@ l7vs_child_process_check(struct l7vs_service_arg_multi *arg)
10181024 * @return OK=0, NG=-1
10191025 */
10201026 int
1021-l7vs_receive_add_protocol_info(int fd)
1027+l7vs_receive_add_protocol_info(int fd, pid_t pid)
10221028 {
10231029 l7vs_service_arg_multi *arg;
10241030 void *buffer;
@@ -1026,6 +1032,8 @@ l7vs_receive_add_protocol_info(int fd)
10261032
10271033 int err;
10281034
1035+ /* 子プロセスでl7vs_service_arg_multiを作る関数 */
1036+
10291037 // buffer確保
10301038 buffer = malloc(sizeof(struct l7vs_service_arg_multi));
10311039 if(buffer == NULL){
@@ -1042,7 +1050,7 @@ l7vs_receive_add_protocol_info(int fd)
10421050 arg = (l7vs_service_arg_multi *)buffer;
10431051
10441052 // l7vs_service作成
1045- srv = make_l7vs_service_data(arg,&err);
1053+ srv = make_l7vs_service_data(arg,&err,pid);
10461054 if(srv == NULL){
10471055 free(buffer);
10481056 return -1;
@@ -1060,7 +1068,7 @@ l7vs_receive_add_protocol_info(int fd)
10601068 * @return int OK=0, NG<0
10611069 */
10621070 static int
1063-l7vs_cfifo_callback(struct l7vs_iomux *iom )
1071+l7vs_cfifo_callback(struct l7vs_iomux *iom)
10641072 {
10651073 int ret;
10661074
@@ -1089,8 +1097,8 @@ l7vs_cfifo_callback(struct l7vs_iomux *iom )
10891097 "in_fuction: int l7vs_cfifo_callback (struct l7vs_iomux *iom) iom = %p",iom);
10901098 }
10911099
1092-
1093- ret = l7vs_receive_add_protocol_info(iom->fd);
1100+ /* 必ず子で起動するはずなので、pidは0固定 */
1101+ ret = l7vs_receive_add_protocol_info(iom->fd,0);
10941102 if(ret==-1){
10951103 return -1;
10961104 }
@@ -1323,6 +1331,7 @@ l7vs_service_create(struct l7vs_service_arg_multi *arg, int *err)
13231331 /* 子プロセスを生成したら親プロセスでIP,portとPIDの対応リストを作る */
13241332
13251333 /* 親プロセスから引き継いだUNIXドメインソケットを閉じる */
1334+ /* 現在、閉じると親プロセスが死ぬ */
13261335 //l7vs_config_close();
13271336
13281337 /* 親プロセス用PIPEを閉じる */
@@ -1332,7 +1341,7 @@ l7vs_service_create(struct l7vs_service_arg_multi *arg, int *err)
13321341 if( pid == 0 ){
13331342 /* ソケット作成 */
13341343 /* 以前はmake_l7vs_service_dataがまるごと入っていた */
1335- srv = make_l7vs_service_data(arg,err);
1344+ srv = make_l7vs_service_data(arg,err,pid);
13361345 if( srv == NULL) return NULL;
13371346
13381347 /* 名前付きパイプ作成 */
@@ -1404,7 +1413,7 @@ l7vs_service_create(struct l7vs_service_arg_multi *arg, int *err)
14041413 l7vs_cfifo_iomux->data = NULL;
14051414 l7vs_cfifo_iomux->callback = l7vs_cfifo_callback;
14061415 l7vs_cfifo_iomux->status = iomux_cfifo_read_waiting;
1407- l7vs_iomux_add( l7vs_cfifo_iomux, iom_read );
1416+ l7vs_iomux_add( l7vs_cfifo_iomux, iom_read);
14081417
14091418 /* 親PIPEを開いてPIDとIP,portを親に通知 */
14101419 /* リトライするかどうか・・・sleepいれる? */
@@ -1445,12 +1454,17 @@ l7vs_service_create(struct l7vs_service_arg_multi *arg, int *err)
14451454
14461455 }else if( pid > 0 ){
14471456 /* 親プロセス処理 */
1457+ // 子プロセス作成ループに入れると、子プロセス個数分親処理が走ってしまう
1458+
1459+ /* VS情報作成 */
1460+ srv = make_l7vs_service_data(arg,err,pid);
1461+ if( srv == NULL) return NULL;
14481462
14491463 /* l7vs_child_proto_grpを初期化作成してリスト登録←複数回を考慮 */
14501464 grp = l7vs_child_proto_grp_init(arg->srv_arg.addr.sin_addr.s_addr,
14511465 arg->srv_arg.addr.sin_port,
14521466 arg->srv_arg.protomod );
1453-
1467+ return srv;
14541468 }else if( pid < 0 ){
14551469 /* 子プロセス作成失敗 */
14561470 //DEBUG output
@@ -1461,6 +1475,17 @@ l7vs_service_create(struct l7vs_service_arg_multi *arg, int *err)
14611475 return NULL;
14621476 }
14631477 }
1478+ }else if(srv_sock_check_flg == 1){
1479+ /* 子プロセス追加なし、VSのみ追加 */
1480+ /* 子プロセスは追加しないけど、親側VS情報は追加 */
1481+ // pidは0以外ならOK
1482+ srv = make_l7vs_service_data(arg,err,1);
1483+ if( srv == NULL) return NULL;
1484+
1485+ return srv;
1486+ }else{
1487+ /* VS重複エラー */
1488+ return NULL;
14641489 }
14651490 }
14661491