int socket(long domain, long type, long protocol) { int ret; OS_mutex_lock(g_main_mutex, &mtx_key); ret = c_socket(domain, type, protocol); /*if the value is not error then add to our array for later reference */ if (-1 != ret) find_add_next_free_socket(ret); OS_mutex_unlock(g_main_mutex, mtx_key); return(ret); }
int c = connect(jsfd, (struct sockaddr *)&server_addr, sizeof(server_addr)); print_error(c, "could not connect to Jserver."); printf("%s\n", "connected to JJJJJJJJ server"); //////////////////// client_fd_list_index = 0; char * sockname = (char*)malloc(sizeof(char)*20); strcpy(sockname, type); strcat(sockname, ".sock"); // usfd = s_socket(AF_LOCAL, SOCK_STREAM, 9999, sockname); usfd = c_socket(AF_LOCAL, SOCK_STREAM, sockname); _connect(usfd, AF_LOCAL, SOCK_STREAM, 0, sockname); // unsfd = ud_accept(usfd); printf("Connected to server. Ready to receive fds.\n"); fflush(stdout); } void *service (void *arg) { while(busy); busy = 1; int nsfd = *(int *)arg;
void server_init(){ if(signal(SIGUSR1, sig_handler) == SIG_ERR){ printf("%s\n", "Error in catching SIGINT"); } services[0].port = 9997; services[1].port = 9998; services[2].port = 9999; services[0].name = (char*)malloc(sizeof(char)*20); services[1].name = (char*)malloc(sizeof(char)*20); services[2].name = (char*)malloc(sizeof(char)*20); strcpy(services[0].name, "c"); strcpy(services[1].name, "s"); strcpy(services[2].name, "e"); services[0].usfd = 0; services[1].usfd = 0; services[2].usfd = 0; services[0].unsfd = 0; services[1].unsfd = 0; services[2].unsfd = 0; services[0].capacity = 3; services[1].capacity = 2; services[2].capacity = 1; services[0].started = 0; services[1].started = 0; services[2].started = 0; // services[0].name = "upper"; // services[1].name = "lower"; // services[2].name = "return"; // signal (ctrl c) to clean up. int i; for( i = 0; i<MAX_SERVICES; i++ ){ services[i].sfd = s_socket(AF_INET, SOCK_STREAM, services[i].port, ""); char * sockname = (char*)malloc(sizeof(char)*20); strcpy(sockname, services[i].name); strcat(sockname, ".sock"); services[i].usfd = c_socket(AF_LOCAL, SOCK_STREAM, sockname); _connect(services[i].usfd, AF_LOCAL, SOCK_STREAM, 0, sockname); printf("Connected to the multiplex %s\n", services[i].name); /////trying to send pid to the multiplex char *msg = (char*)malloc(sizeof(char)*200); sprintf(msg, "%d", getpid()); int s = send(services[i].usfd, msg, strlen(msg), 0); print_error(s, "Failed to send initial message"); // int pid = getpid(); // send_fd_extra(services[i].usfd, services[i].sfd, (void*)&pid); //sending pid for further signaling. sleep(2); } printf("%s\n", "Server is initiated."); }