static void deliver_msg_data(consensus_component* comp,view_stamp* vs){ // in order to accelerate deliver process of the program // we may just give the record number instead of the real data // to the proxy, and then the proxy will take the overhead of database operation db_key_type vstokey = vstol(vs); if(comp->deliver_mode==1) { request_record* data = NULL; size_t data_size=0; retrieve_record(comp->db_ptr,sizeof(db_key_type),&vstokey,&data_size,(void**)&data); SYS_LOG(comp,"Node %d Deliver View Stamp %u : %u To The User.\n", comp->node_id,vs->view_id,vs->req_id); STAT_LOG(comp,"Request:%lu\n",vstokey); if(NULL!=data){ if(comp->ucb!=NULL){ comp->ucb(data->data_size,data->data,comp->up_para); }else{ SYS_LOG(comp,"No Such Call Back Func.\n"); } } }else{ STAT_LOG(comp,"Request %lu.\n",vstokey); if(comp->ucb!=NULL){ comp->ucb(sizeof(db_key_type),&vstokey,comp->up_para); }else{ SYS_LOG(comp,"No Such Call Back Func.\n"); } } return; }
/** * @brief Connects to the host * * @param sess Session Context * TODO - Move allocation part to separate function * To enable one time allocation of server context * * @return Error Code */ static inline rtsp_error_t rtspc_connect(rtsp_session_t *sess){ struct addrinfo hints; struct addrinfo *result, *rp; int const service_len = 32; char service[service_len]; int ret = -1; if(!sess){ return (RTSP_E_INVALID_ARG); } /* * Function will be called only valid url structure is present */ service[service_len-1]= '\0'; strcpy(service, "rtsp"); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; /* IPv4 or IPv6 */ hints.ai_flags = 0; hints.ai_protocol = 0; switch(sess->rtsp_url.type){ case RTSP_NW_TCP: hints.ai_socktype = SOCK_STREAM; break; case RTSP_NW_STAR: case RTSP_NW_UDP: default: ERR_LOG("URI Not supported"); return (RTSP_E_UNSUPPORTED); break; } if(sess->rtsp_url.port > 0){ snprintf(service, service_len,"%u", sess->rtsp_url.port); hints.ai_flags = AI_NUMERICSERV; } else { /* Default rtsp service name will pick default port * configured in the system /etc/services */ } ret = getaddrinfo(sess->rtsp_url.host,service, &hints, &result); if (ret != 0) { ERR_LOG("getaddrinfo: %s\n", gai_strerror(ret)); return (RTSP_E_FAILURE); } /* * Connect to address * get Socket fd */ for (rp = result; rp != NULL; rp = rp->ai_next){ sess->sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (sess->sfd == -1) continue; if (connect(sess->sfd, rp->ai_addr, rp->ai_addrlen) != -1) break; /* Success */ close(sess->sfd); } freeaddrinfo(result); if(rp == NULL){ ERR_LOG("Could not connect to host '%s'", sess->rtsp_url.host); return (RTSP_E_FAILURE); } if(0 != set_non_blocking_socket (sess->sfd)){ ERR_LOG("Cannot Set Socket as Non-Blocking"); return (RTSP_E_FAILURE); } STAT_LOG("Connected to host '%s'", sess->rtsp_url.host); return (RTSP_E_SUCCESS); }