void Cli_Port_Manager:: thread_body(base_socket cli_sock){ cout<<"---------------------------------------------------------------------------"<<endl; cout<<"---------------------------------------------------------------------------"<<endl; cout<<"Thread Cli_Port_Manager started"<<endl; cout<<"Thread id "<<this_thread::get_id()<<endl; int ctrl; string service_name; string buff; ctrl=cli_sock.recv_msg(buff); if (ctrl<0) cout<<"Cli_Port_Manager:: error receaving message"<<endl; service_name=buff; cout<<service_name<<endl; string signature=""; string ip=""; int port; string msg; if(list_manager->choose_sp(service_name, &ip,&port,&signature)==0){ ctrl=create_msg(msg,"","|",ip,port,signature); if (ctrl!=0) cout<<"Cli_Port_Manager:: error creating message for client"<<endl; } else{ msg="Error: No services named "; msg+=service_name; msg+=" available"; } ctrl=cli_sock.send_msg(msg); if (ctrl<0) cout<<"Cli_Port_Manager:: error sending message"<<endl; else{ cout<<"message ' "<<msg<<" ' sended"<<endl; } cli_sock.Close(); cout<<endl<<"Fine thread SP_Port_Manager"<<endl; unlock_accept(); }
void recv_packet (base_socket& socket, void* buffer, size_t bufsize) { char* bufptr = (char*) buffer; size_t ntorecv = bufsize; do { size_t nbytes = socket.recv (bufptr, ntorecv); if (nbytes == 0) throw socket_error ("socket.recv is closed"); bufptr += nbytes; ntorecv -= nbytes; }while (ntorecv > 0); }
void send_packet (base_socket& socket, const void* buffer, size_t bufsize) { const char* bufptr = (const char*) buffer; size_t ntosend = bufsize; do { size_t nbytes = socket.send (bufptr, ntosend); bufptr += nbytes; ntosend -= nbytes; }while (ntosend > 0); }
void send_packet (base_socket& socket, const void* buffer, size_t bufsize) { const char* bufptr = static_cast<const char*> (buffer); ssize_t ntosend = bufsize; do { ssize_t nbytes = socket.send (bufptr, ntosend); if (nbytes < 0) throw socket_sys_error (to_string (socket)); bufptr += nbytes; ntosend -= nbytes; }while (ntosend > 0); }
void recv_packet (base_socket& socket, void* buffer, size_t bufsize) { char* bufptr = static_cast<char*> (buffer); ssize_t ntorecv = bufsize; do { ssize_t nbytes = socket.recv (bufptr, ntorecv); if (nbytes < 0) throw socket_sys_error (to_string (socket)); if (nbytes == 0) throw socket_error (to_string (socket) + " is closed"); bufptr += nbytes; ntorecv -= nbytes; }while (ntorecv > 0); }