int oe_server_receive_tmo(CORBA_Environment *env, oe_map_t *map, unsigned int send_ms, unsigned int recv_ms) { int res = 0, loop = 1; erlang_msg msg; while (res >= 0 && loop > 0) { res = ei_receive_encoded_tmo(env->_fd, &env->_inbuf, &env->_inbufsz, &msg, &env->_iin, recv_ms); switch(res) { case ERL_SEND: case ERL_REG_SEND: oe_exec_switch(NULL, env, map); switch(env->_major) { case CORBA_NO_EXCEPTION: break; case CORBA_SYSTEM_EXCEPTION: /* XXX stderr */ fprintf(stderr, "Request failure, reason : %s\n", (char *) CORBA_exception_value(env)); CORBA_exception_free(env); break; default: /* Should not happen */ CORBA_exception_free(env); break; } /* send reply */ /* XXX We are required to set env->_iout = 0 if oneway?? */ if (env->_iout > 0) ei_send_encoded_tmo(env->_fd, &env->_caller, env->_outbuf, env->_iout, send_ms); loop = 0; break; case ERL_TICK: break; default: /* XXX */ if (res < 0) { fprintf(stderr, "Result negative: %d\n", res); loop = 0; } break; } } return 0; }
/* Client send message (Erlang distribution protocol) */ static int oe_send_tmo(CORBA_Environment *env, unsigned int ms) { if (strlen(env->_regname) == 0) { if (ei_send_encoded_tmo(env->_fd, env->_to_pid, env->_outbuf, env->_iout, ms) < 0) { /* XXX Cannot send to peer? */ CORBA_exc_set(env, CORBA_SYSTEM_EXCEPTION, NO_RESPONSE, "Cannot connect to server"); return -1; } } else { if (ei_send_reg_encoded_tmo(env->_fd, env->_from_pid, env->_regname, env->_outbuf, env->_iout, ms) < 0) { /* XXX Cannot send to peer? */ CORBA_exc_set(env, CORBA_SYSTEM_EXCEPTION, NO_RESPONSE, "Cannot connect to server"); return -1; } } return 0; }
int ei_send_encoded(int fd, const erlang_pid *to, char *msg, int msglen) { return ei_send_encoded_tmo(fd, to, msg, msglen, 0); }
/* * Sends an Erlang message to a process at an Erlang node */ int ei_send_tmo(int fd, erlang_pid* to, char* buf, int len, unsigned ms) { /* erl_errno and return code is set by ei_reg_send_encoded_tmo() */ return ei_send_encoded_tmo(fd, to, buf, len, ms); }