From 640cfa549d13d5d04f8151f3b2a80b0d5e7c18ea Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 27 May 2009 17:32:18 +0200 Subject: [PATCH] forb_request_send() moved to iop.c The reason is that we want all inter-orb protocol related messages in the same log domain. --- src/iop.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/iop.h | 4 +++ src/request.c | 72 ----------------------------------------------- src/request.h | 3 -- 4 files changed, 82 insertions(+), 75 deletions(-) diff --git a/src/iop.c b/src/iop.c index 4aa8131..90c6e9d 100644 --- a/src/iop.c +++ b/src/iop.c @@ -107,6 +107,10 @@ forb_iop_prepare_request(forb_request_t *req, if (ret) { /* Request body is 8 byte aligned */ ret = FORB_CDR_put_align(&req->cdr_request, 8); + char str[50]; + ul_logdeb("preparing request: id=%d dest=%s iface=%s method=%d\n", req->request_id, + forb_server_id_to_string(str, &req->obj->server, sizeof(str)), + iface, method_ind); } return ret; } @@ -610,3 +614,77 @@ void *forb_iop_discovery_thread(void *arg) pthread_cleanup_pop(1); return NULL; } + +/** + * Sends REQUEST message to another FORB. + * + * The request @a req has to be prepared by + * forb_iop_prepare_request(). Then, this function adds a message + * header, connects to the destination FORB and sends the request. + * + * If no exception is reported, then the caller must wait for response + * by calling forb_wait_for_reply(). + * + * @param req A request prepared by forb_iop_prepare_request() + * @param env Environment for returning exceptions + */ +void +forb_request_send(forb_request_t *req, CORBA_Environment *env) +{ + CORBA_boolean ret; + forb_peer_t *peer; + ssize_t size; + size_t len; + fosa_abs_time_t timeout; + forb_t *forb = forb_object_to_forb(req->obj); + + if (!forb) { + env->major = FORB_EX_INTERNAL; + return; + } + + req->env = env; /* Remember, where to return exceptions */ + + ret = forb_iop_prepend_message_header(&req->cdr_request, forb_iop_REQUEST); + if (!ret) { + /* This should never happen */ + env->major = FORB_EX_INTERNAL; + return; + } + + fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout); + timeout = fosa_abs_time_incr(timeout, + fosa_msec_to_rel_time(1000)); + peer = forb_get_next_hop(forb, &req->obj->server, &timeout); + if (!peer) { + char str[50]; + ul_logerr("Cannot find peer to send request for server %s\n", + forb_server_id_to_string(str, &req->obj->server, sizeof(str))); + env->major = FORB_EX_COMM_FAILURE; + return; + } + /* Register the request with forb so we can match incomming + * reply to this request. */ + ret = forb_request_insert(forb, req); + if (ret <= 0) { + ul_logerr("Insert request error %d\n", ret); + env->major = FORB_EX_INTERNAL; + goto err_peer_put; + } + + { + char str[50]; + ul_logdeb("sending request: id=%d dest=%s\n", req->request_id, + forb_server_id_to_string(str, &req->obj->server, sizeof(str))); + } + len = FORB_CDR_data_size(&req->cdr_request); + fosa_mutex_lock(&peer->send_lock); + size = forb_proto_send(peer, &req->cdr_request); + fosa_mutex_unlock(&peer->send_lock); + if (size <= 0 || size != len) { + env->major = FORB_EX_COMM_FAILURE; + /* Request is deleted when the stub calls forb_request_destroy() */ + } + err_peer_put: + forb_peer_put(peer); +} diff --git a/src/iop.h b/src/iop.h index 190563c..4dc764c 100644 --- a/src/iop.h +++ b/src/iop.h @@ -88,4 +88,8 @@ forb_iop_receiver_thread(void *arg); void * forb_iop_discovery_thread(void *arg); +/* TODO: rename to forb_iop_send_request */ +void +forb_request_send(forb_request_t *req, CORBA_Environment *env); + #endif diff --git a/src/request.c b/src/request.c index 5118339..b6b1196 100644 --- a/src/request.c +++ b/src/request.c @@ -160,75 +160,3 @@ forb_request_signal_processed(forb_request_t *req) forb_syncobj_signal(req->reply_processed); } -/** - * Sends REQUEST message to another FORB. - * - * The request @a req has to be prepared by - * forb_iop_prepare_request(). Then, this function adds a message - * header, connects to the destination FORB and sends the request. - * - * If no exception is reported, then the caller must wait for response - * by calling forb_wait_for_reply(). - * - * @param req A request prepared by forb_iop_prepare_request() - * @param env Environment for returning exceptions - */ -void -forb_request_send(forb_request_t *req, CORBA_Environment *env) -{ - CORBA_boolean ret; - forb_peer_t *peer; - size_t size, len; - fosa_abs_time_t timeout; - forb_t *forb = forb_object_to_forb(req->obj); - - if (!forb) { - env->major = FORB_EX_INTERNAL; - return; - } - - req->env = env; /* Remember, where to return exceptions */ - - ret = forb_iop_prepend_message_header(&req->cdr_request, forb_iop_REQUEST); - if (!ret) { - /* This should never happen */ - env->major = FORB_EX_INTERNAL; - return; - } - - fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout); - timeout = fosa_abs_time_incr(timeout, - fosa_msec_to_rel_time(1000)); - peer = forb_get_next_hop(forb, &req->obj->server, &timeout); - if (!peer) { - char str[50]; - ul_logerr("Cannot find peer to send request for server %s\n", - forb_server_id_to_string(str, &req->obj->server, sizeof(str))); - env->major = FORB_EX_COMM_FAILURE; - return; - } - /* Register the request with forb so we can match incomming - * reply to this request. */ - ret = forb_request_insert(forb, req); - if (ret <= 0) { - ul_logerr("Insert request error %d\n", ret); - env->major = FORB_EX_INTERNAL; - goto err_peer_put; - } - - { - char str[50]; - ul_logdeb("sending request: id=%d dest=%s\n", req->request_id, - forb_server_id_to_string(str, &req->obj->server, sizeof(str))); - } - len = FORB_CDR_data_size(&req->cdr_request); - fosa_mutex_lock(&peer->send_lock); - size = forb_proto_send(peer, &req->cdr_request); - fosa_mutex_unlock(&peer->send_lock); - if (size <= 0 || size != len) { - env->major = FORB_EX_COMM_FAILURE; - /* Request is deleted when the stub calls forb_request_destroy() */ - } - err_peer_put: - forb_peer_put(peer); -} diff --git a/src/request.h b/src/request.h index 0458760..1b1d0fc 100644 --- a/src/request.h +++ b/src/request.h @@ -134,8 +134,5 @@ void forb_request_wait_for_reply(forb_request_t *req); void forb_request_signal_processed(forb_request_t *req); -void -forb_request_send(forb_request_t *req, CORBA_Environment *env); - #endif -- 2.39.2