- unsigned int sz;
- int nsock,max=0,on, nr, si, sj;
- struct sockaddr_in svr;
- fd_set rset;
- NETlink *pomlink;
- INTlink *pomlink2;
- struct sockaddr_un svr2;
- MESSAGE msg;
-
-
- FD_ZERO(&rset);
- FD_SET(listen_sock,&rset);
- max = listen_sock;
- FD_SET(kernel_sock,&rset);
- if (max<kernel_sock) { max=kernel_sock;}
- pomlink2 = Interpreters.first();
- while (pomlink2!=NULL)
- {
- FD_SET(pomlink2->sock,&rset);
- if (max<pomlink2->sock) max=pomlink2->sock;
- pomlink2=Interpreters.next();
- }
- pomlink = Links.first();
- while (pomlink!=NULL)
- {
- if (pomlink->connected)
- {
- FD_SET(pomlink->sock,&rset);
- if (max<pomlink->sock) max=pomlink->sock;
- }
- pomlink=Links.next();
- }
-
- // odczyt
- if (select(max+1,&rset,0,0,NULL) > 0) {
- // accept connection
- if (FD_ISSET(listen_sock,&rset))
- {
- /* accept connection on listen socket */
- sz = sizeof(svr);
- bzero(&svr, sizeof(svr));
- nsock = accept(listen_sock, (struct sockaddr*)&svr, &sz);
- if (nsock>0)
- {
- pomlink = new NETlink;
- strcpy(pomlink->addr,inet_ntoa(svr.sin_addr));
- pomlink->sock = nsock;
- pomlink->connected = TRUE;
- fcntl(pomlink->sock, F_SETFL,O_NONBLOCK | fcntl(pomlink->sock,F_GETFL,0));
- on=1;
- setsockopt(pomlink->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
- Links.append(pomlink);
- } /* nsock > 0 */
- } /* ISSET */
-
- // get internal message
- /* Check request sockets */
- pomlink2 = Interpreters.first();
- while (pomlink2!=NULL)
- {
- if (FD_ISSET(pomlink2->sock,&rset))
- {
- nr = read(pomlink2->sock,&msg,sizeof(MESSAGE));
- if (nr>0)
- {
- if (msg.msg_type == MSG_NET)
- switch(msg.param.pword[0])
- {
- case NET_PROPAGATE:propagate_msg(&msg); break;
- case NET_NODE_EXIST:check_node(msg.param.pword[1],pomlink2->sock);break;
- case NET_GET_INFO: conn_info(pomlink2->sock);break;
- case NET_NODES_NUM: msg.param.pword[0]=NET_NODES_NUM_RESPONSE;
- msg.param.pword[1]=Links.count();
- write(pomlink2->sock,&msg,sizeof(MESSAGE));
- break;
- }/* switch */
- }
- } /* ISSET */
- pomlink2=Interpreters.next();
- } // while
- /* Check internal socket */
- if (FD_ISSET(kernel_sock,&rset))
- {
- nr = read(kernel_sock, &msg, sizeof(MESSAGE));
- if (nr>0)
- {
- if (msg.msg_type == MSG_NET)
- {
- switch(msg.param.pword[0])
- {
- case NET_TRANSMIT_CODE:
-
- transmit_file(msg.param.pword[2],msg.param.pstr,msg.param.pword[1]);
-
- break;
- case NET_EXIT: { disconnect_seq();exit_sequence();}
- break;
- case NET_GET_INFO: conn_info(kernel_sock);break;
- case NET_PROPAGATE:propagate_msg(&msg);break;
- case NET_DISCONNECT:disconnect_seq();
- break;
- case NET_NODE_EXIST: check_node(msg.param.pword[1],kernel_sock);break;
- case NET_CONNECT_TO: connect_seq(msg.param.pstr);
- } /* end switch */
- } /* MSG_NET */
- if (msg.msg_type == MSG_VLP)
- switch(msg.param.pword[0])
- {
- case VLP_REGINT:
- {
-
- pomlink2 = new INTlink;
- pomlink2->sock = socket(AF_UNIX,SOCK_STREAM,0);
- bzero(&svr2,sizeof(svr2));
- svr2.sun_family = AF_UNIX;
- strcpy(svr2.sun_path,msg.param.pstr);
- si = strlen(svr2.sun_path)+sizeof(svr2.sun_family);
- sj = connect(pomlink2->sock,(struct sockaddr*)&svr2,si);
- if (sj==0)
- fcntl(pomlink2->sock,F_SETFL, O_NONBLOCK|fcntl(pomlink2->sock,F_GETFL,0));
- int on=1;
- setsockopt(pomlink2->sock,IPPROTO_TCP,TCP_NODELAY,(char*)&on,sizeof(on));
- pomlink2->ID = msg.param.pword[1];
- pomlink2->connected=TRUE;
- Interpreters.append(pomlink2);
-
- };break;
- case VLP_INTERPRETER_DOWN:
- {
-
- pomlink2 = findINTlink(msg.param.pword[1]);
- if (pomlink2!=NULL)
- {
- close(pomlink2->sock);
- Interpreters.remove(pomlink2);
- }
- };break;
- } /* MSg_VLP */
- } // nr > 0
- }/* ISSET */
-
- // get remote message
-
- pomlink=Links.first();
- while (pomlink!=NULL)
- {
- if (FD_ISSET(pomlink->sock,&rset)) get_message(pomlink);
- pomlink=Links.next();
- }
- } // select
-
-
+ unsigned int sz;
+ int nsock,max = 0, on, nr, si, sj;
+ struct sockaddr_in svr;
+ fd_set rset;
+ NETlink *pomlink;
+ INTlink *pomlink2;
+ struct sockaddr_un svr2;
+ MESSAGE msg;
+
+ FD_ZERO(&rset);
+ FD_SET(listen_sock, &rset);
+ max = listen_sock;
+ FD_SET(kernel_sock, &rset);
+ if (max < kernel_sock) {
+ max=kernel_sock;
+ }
+ pomlink2 = Interpreters.first();
+ while (pomlink2 != NULL) {
+ FD_SET(pomlink2->sock, &rset);
+ if (max < pomlink2->sock) {
+ max=pomlink2->sock;
+ }
+ pomlink2 = Interpreters.next();
+ }
+ pomlink = Links.first();
+ while (pomlink != NULL) {
+ if (pomlink->connected) {
+ FD_SET(pomlink->sock, &rset);
+ if (max < pomlink->sock) {
+ max = pomlink->sock;
+ }
+ }
+ pomlink=Links.next();
+ }
+
+ /* odczyt */
+ if (select(max + 1, &rset, 0, 0, NULL) > 0) {
+ /* accept connection */
+ if (FD_ISSET(listen_sock,&rset)) {
+ /* accept connection on listen socket */
+ sz = sizeof(svr);
+ bzero(&svr, sizeof(svr));
+ nsock = accept(listen_sock, (struct sockaddr*)&svr, &sz);
+ if (nsock > 0) {
+ pomlink = new NETlink;
+ strcpy(pomlink->addr, inet_ntoa(svr.sin_addr));
+ pomlink->sock = nsock;
+ pomlink->connected = TRUE;
+ fcntl(pomlink->sock, F_SETFL,O_NONBLOCK |
+ fcntl(pomlink->sock, F_GETFL, 0));
+ on = 1;
+ setsockopt(pomlink->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
+ Links.append(pomlink);
+ } /* nsock > 0 */
+ } /* ISSET */
+
+ /* get internal message*/
+ /* Check request sockets */
+ pomlink2 = Interpreters.first();
+ while (pomlink2 != NULL) {
+ if (FD_ISSET(pomlink2->sock,&rset)) {
+ nr = read(pomlink2->sock, &msg, sizeof(MESSAGE));
+ if (nr > 0) {
+ if (msg.msg_type == MSG_NET) {
+ switch(msg.param.pword[0]) {
+ case NET_PROPAGATE:
+ propagate_msg(&msg);
+ break;
+ case NET_NODE_EXIST:
+ check_node(msg.param.pword[1], pomlink2->sock);
+ break;
+ case NET_GET_INFO:
+ conn_info(pomlink2->sock);
+ break;
+ case NET_NODES_NUM:
+ msg.param.pword[0] = NET_NODES_NUM_RESPONSE;
+ msg.param.pword[1] = Links.count();
+ write(pomlink2->sock, &msg, sizeof(MESSAGE));
+ break;
+ }/* switch */
+ }
+ }
+ }/* ISSET */
+ pomlink2 = Interpreters.next();
+ }/* while */
+
+ /* Check internal socket */
+ if (FD_ISSET(kernel_sock, &rset)) {
+ nr = read(kernel_sock, &msg, sizeof(MESSAGE));
+ if (nr > 0) {
+ if (msg.msg_type == MSG_NET) {
+ switch(msg.param.pword[0]) {
+ case NET_TRANSMIT_CODE:
+ transmit_file(msg.param.pword[2], msg.param.pstr, msg.param.pword[1]);
+ break;
+ case NET_EXIT:
+ disconnect_seq();
+ exit_sequence();
+ break;
+ case NET_GET_INFO:
+ conn_info(kernel_sock);
+ break;
+ case NET_PROPAGATE:
+ propagate_msg(&msg);
+ break;
+ case NET_DISCONNECT:
+ disconnect_seq();
+ break;
+ case NET_NODE_EXIST:
+ check_node(msg.param.pword[1], kernel_sock);
+ break;
+ case NET_CONNECT_TO:
+ connect_seq(msg.param.pstr);
+ } /* end switch */
+ } /* MSG_NET */
+ if (msg.msg_type == MSG_VLP) {
+ switch(msg.param.pword[0]) {
+ case VLP_REGINT: {
+ pomlink2 = new INTlink;
+ pomlink2->sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ bzero(&svr2, sizeof(svr2));
+ svr2.sun_family = AF_UNIX;
+ strcpy(svr2.sun_path, msg.param.pstr);
+ si = strlen(svr2.sun_path) + sizeof(svr2.sun_family);
+ sj = connect(pomlink2->sock,(struct sockaddr*)&svr2, si);
+ if (sj == 0)
+ fcntl(pomlink2->sock,F_SETFL, O_NONBLOCK | fcntl(pomlink2->sock, F_GETFL, 0));
+ int on = 1;
+ setsockopt(pomlink2->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on));
+ pomlink2->ID = msg.param.pword[1];
+ pomlink2->connected = TRUE;
+ Interpreters.append(pomlink2);
+ };
+ break;
+ case VLP_INTERPRETER_DOWN: {
+ pomlink2 = findINTlink(msg.param.pword[1]);
+ if (pomlink2 != NULL) {
+ close(pomlink2->sock);
+ Interpreters.remove(pomlink2);
+ }
+ };
+ break;
+ } /* MSg_VLP */
+ }
+ } /* nr > 0 */
+ }/* ISSET */
+
+ /* get remote message*/
+
+ pomlink=Links.first();
+ while (pomlink != NULL) {
+ if (FD_ISSET(pomlink->sock, &rset))
+ get_message(pomlink);
+ pomlink=Links.next();
+ }
+ } // select