static void * proto_server_req_dispatcher(void * arg) { Proto_Session s; Proto_Msg_Types mt; Proto_MT_Handler hdlr; int i; unsigned long arg_value = (unsigned long) arg; pthread_detach(pthread_self()); proto_session_init(&s); s.fd = (FDType) arg_value; fprintf(stderr, "proto_rpc_dispatcher: %p: Started: fd=%d\n", pthread_self(), s.fd); for (;;) { if (proto_session_rcv_msg(&s)==1) { mt = proto_session_hdr_unmarshall_type(&s); if (mt > PROTO_MT_REQ_BASE_RESERVED_FIRST && mt < PROTO_MT_REQ_BASE_RESERVED_LAST) { hdlr = Proto_Server.base_req_handlers[mt]; if (hdlr(&s)<0) goto leave; } } else { goto leave; } } leave: Proto_Server.session_lost_handler(&s); close(s.fd); return NULL; }
static void * proto_client_event_dispatcher(void * arg) { Proto_Client *c; Proto_Session *s; Proto_Msg_Types mt; Proto_MT_Handler hdlr; pthread_detach(pthread_self()); /*NOT_IMPL;i*/ c = arg; s = &(c->event_session); for (;;) { if (proto_session_rcv_msg(s)==1) { mt = proto_session_hdr_unmarshall_type(s); if (mt > PROTO_MT_EVENT_BASE_RESERVED_FIRST && mt < PROTO_MT_EVENT_BASE_RESERVED_LAST) { hdlr = c->base_event_handlers[mt-PROTO_MT_EVENT_BASE_RESERVED_FIRST-1]; /*NOT_IMPL;//ADD CODE*/ if (hdlr(s)<0) goto leave; } } else { c->session_lost_handler(s); /*NOT_IMPL;//ADD CODE*/ goto leave; } } leave: close(s->fd); return NULL; }
extern int proto_session_rpc(Proto_Session *s){ int rc=0; proto_session_send_msg(s, 1); rc = proto_session_rcv_msg(s); return rc; }
extern int proto_session_rpc(Proto_Session *s) { int rc; rc = proto_session_send_msg(s,1); if (rc==1) { rc = proto_session_rcv_msg(s); } return rc; }
extern int proto_session_rpc(Proto_Session *s) { int rc; // HACK // fprintf(stderr, "Sent bytes:\n", ); // print_mem(&s->shdr, sizeof(Proto_Msg_Hdr)); rc = proto_session_send_msg(s, 0); rc = proto_session_rcv_msg(s); // fprintf(stderr, "Rcv msg returns : %d\n", rc); return rc; }
extern int proto_session_rpc(Proto_Session *s) { int rc; if (proto_session_send_msg(s, 1) != -1) { rc = proto_session_rcv_msg(s); } else { rc = -1; } return rc; }
//This function is used for RPC's that do not contain anything in the body //Parameter: Proto_Msg_Hdr ch - that contains all necessary information for the RPC // Proto_Client_Handle *h - Handle to the Proto_Client //Returns: Return Code - as specified in Game_Error_Types in types.h extern int do_no_body_rpc(Proto_Client_Handle ch, Proto_Msg_Hdr * h) { int rc; Proto_Session *s; Proto_Client *c = ch; s = &(c->rpc_session); proto_session_hdr_marshall(s,h); rc = proto_session_send_msg(s,1); rc = proto_session_rcv_msg(s); if(rc<=0) rc =-1; return rc; }
extern int proto_session_rpc(Proto_Session *s) { int rc; // ADD CODE int n1; int n2; n1 = proto_session_send_msg(s, 1); if (n1 != 1) { printf("prote_session_rpc error: sending messge"); return -1; } n2 = proto_session_rcv_msg(s); if (n2 == 1) rc = 1; else rc = -1; return rc; }
//This function is used for RPC's that do not contain anything in the body //Parameter: Proto_Msg_Hdr *h - that contains all necessary information for the RPC // Proto_Client_Handle ch - Handle to the Proto_Client // Pos current - current position of the player // Pos next - next position that the players wants to move to //Returns: Return Code - as specified in Game_Error_Types in types.h extern int do_action_request_rpc(Proto_Client_Handle ch, Proto_Msg_Hdr * hdr,Pos current, Pos next) { int rc; Proto_Session *s; Proto_Client *c = ch; s = &(c->rpc_session); proto_session_hdr_marshall(s,hdr); if( hdr->gstate.v1.raw >= ACTION_MOVE && hdr->gstate.v1.raw <= ACTION_PICKUP_SHOVEL) { proto_session_body_marshall_bytes(s,sizeof(Pos),(char*)¤t); proto_session_body_marshall_bytes(s,sizeof(Pos),(char*)&next); } rc = proto_session_send_msg(s,1); rc = proto_session_rcv_msg(s); if(rc<=0) rc =-1; return rc; }