How do I close a socket from another socket in C (using switch)? -


i'm using select() along openssl open multiple sockets on generic tcp server. have pretty standard setup using pool of of file descriptors listening on each socket individually using

int sd = client_socket[id]; /* add new socket array of sockets */ (i = 0; < max_connections; i++) {     /* if position empty */     if (client_socket[i] == 0) {         client_socket[i] = new_socket;         client_ssl_sockets[i] = *ssl; //save ssl object array         break;     } } 

what want issue command client force close client's socket. i'm using

void kill_socket(int id) {     close(client_socket[id]);     client_socket[id] = 0; } 

unfortunately above closes socket - if supply no id argument. there way able reference specific socket in pool of sockets isolate , close issued command?

clarification edit: when command issued client mean text string being taken in via ssl_read , being used switch statement such:

ret_status = ssl_read(ssl, buf, max_buf);  strncpy(pre, buf, 2); /* pull first 2 characters of buffer */ strcpy(var, buf + 2); /* pull rest of characters buffer function argument (where applicable) */  cmd = atoi(pre); /* convert buffer prefix integer switch */  switch (cmd) {     ... } 

then can have client execute command (and pass argument function var string above.

the problem see close() function being called inside for loop responsible specific socket , can't see other sockets. how make socket visible (and interactive) other sockets?

edit: switch statement calling kill_socket() function requested @remy

case 98: /* disconnect node */     if (check_auth(client_ip[i]) == 1) {         printf("closing client connection!\n\n");         kill_socket(atoi(var));      } else {         printf("you must authenticate first!\n\n");      }       break; 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -