void grapher::add(const processed_object& po) { require_not_generated(); if (po.connection()) { process_connections(po); return; } const auto v(vertex_for_id(po.id())); graph_[v] = po; process_child_node(v, po); }
int main (int argc, char *argv[]) { struct sockaddr_in server, client; int s, server_port; char *code; logfile = fopen(FILE_NAME, "w+"); signal(SIGINT, end_server); signal(SIGTERM, end_server); if(argc >= 2){ server_port = atoi(argv[1]); } else { fprintf(stderr, "Usage :server portnumber\n"); exit(1); } /* Get the code if its provided*/ if(argc==3){ int codelen = strlen(argv[2]); if(codelen < NUM_CHOOSEN){ fprintf(stderr, "No enough characters for code\n"); exit(1); } else { code = malloc(sizeof(char)*NUM_CHOOSEN); strncpy(code, argv[2], NUM_CHOOSEN); } } else { code = NULL; } printf("Server port %i\n",server_port); /* Building data structures for sockets */ /* Identify two end points; one for the server and the other for the client when it connects to the server socket */ memset (&server,0, sizeof (server)); /* Server socket initializations */ /* AF_INET: specifies the connection to Internet. In our example we use TCP port 5431 as the known server port; Any client need to connect to this port; INADDR_ANY specifies the server is willing to accept connections on any of the local host's IP addresses. */ server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons (server_port); /* Preliminary server steps: Setup: creation of passive open socket*/ if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) { perror ("Error creating socket"); exit (1); } printf("Socket descriptor: %d\n", s); /* Bind the socket to local address */ if (bind (s, (struct sockaddr *) &server, sizeof (server)) < 0) { perror ("Error in binding to the specified port"); exit (1); } printf("sock: family = %d\n", server.sin_family); printf(" saddr = %d\n", server.sin_addr.s_addr); printf(" port = %d\n", ntohs(server.sin_port)); /* Sets the maximum number of pending connections to be allowed, in our case this number is 10 */ if ( listen (s, 5) < 0) { perror("listen() failed with error"); exit(1); } else { printf("Listening on port %d...\n", ntohs(server.sin_port)); } process_connections(s, code); return 1; }