int send_msg_to_db_ex(Csprite* p, userid_t id, uint16_t cmd, Cmessage * c_in ) { if (proxysvr_fd == -1) { proxysvr_fd = connect_to_service(config_get_strval("service_dbproxy"), 0, 65535, 1); } if ((proxysvr_fd == -1) ) { KDEBUG_LOG(id, "send to dbproxy failed: fd=%d ", proxysvr_fd ); if (p) { if (p->get_waitcmd()== cli_login_cmd) { return -1; } return p->send_err( cli_err_system_error ); } return 0; } static char dbbuf[ sizeof(db_proto_t) ]; db_proto_t* pkg = (db_proto_t*)dbbuf; pkg->len = sizeof(db_proto_t); pkg->seq = (p ? ((p->fdsess->fd << 16) | p->get_waitcmd()) : 0); pkg->cmd = cmd; pkg->ret = 0; pkg->id = id; KDEBUG_LOG(pkg->id,"SO[0x%04X]",pkg->cmd ); return net_send_msg(proxysvr_fd, (char*)dbbuf, c_in ); }
int send_request_to_db(userid_t id, uint16_t cmd, const void* body_buf, int body_len) { assert(body_len >= 0); static uint8_t dbbuf[pkg_size]; if (proxysvr_fd == -1) { proxysvr_fd = connect_to_service(config_get_strval("dbproxy_ip"), 0, 65535, 1); } uint32_t len = sizeof(svr_proto_t) + body_len; if ((proxysvr_fd == -1) || (len > sizeof(dbbuf))) { ERROR_LOG("send to dbproxy failed: fd=%d len=%d", proxysvr_fd, len); return -1; } svr_proto_t* pkg = reinterpret_cast<svr_proto_t*>(dbbuf); pkg->len = len; pkg->seq = 0; pkg->cmd = cmd; pkg->ret = 0; pkg->id = id; memcpy(pkg->body, body_buf, body_len); return net_send(proxysvr_fd, dbbuf, len); }
/** * @brief connect to switch and send an init package of online information when online is launched */ void connect_to_switch() { DEBUG_LOG("do connect_to_switch"); switch_fd = connect_to_service(config_get_strval("service_switch"), 0, 65535, 1); if (switch_fd != -1) { //连上时 is_add_timer_to_connect_switch=false; static uint32_t seqno = 0; sw_report_online_info_in sw_in; sw_in.domain_id= config_get_intval("domain", 0); sw_in.online_id= get_server_id(); memcpy(sw_in.online_name,get_server_name(),sizeof(sw_in.online_name)); memcpy(sw_in.online_ip,get_server_ip(),sizeof(sw_in.online_ip)); sw_in.online_port=get_server_port(); sw_in.seqno=seqno; g_sprite_map->get_userid_list(sw_in.userid_list); sw_in.user_num=sw_in.userid_list.size() ; ++seqno; send_msg_to_switch(NULL,sw_report_online_info_cmd,0,&sw_in ); KDEBUG_LOG(0, "BEGIN CONNECTING TO CENTRAL ONLINE AND SEND INIT PKG"); }else{// if(! is_add_timer_to_connect_switch){//还没有加入定时器 DEBUG_LOG("ADD TIMER connect_switch "); g_timer_map->add_timer( TimeVal(3),n_sw_report_online_info,0 ); is_add_timer_to_connect_switch=true; } } }
int main() { char service_name[256]; printf("Input service name you want to connect:\n"); fgets(service_name, sizeof(service_name), stdin); if (service_name[strlen(service_name) - 1] == '\n') service_name[strlen(service_name) - 1] = '\0'; if (!connect_to_service(service_name)) { fprintf(stderr, "connect_to_service failed\n"); exit(EXIT_FAILURE); } if (!read_info()) { fprintf(stderr, "read_info failed\n"); exit(EXIT_FAILURE); } if (socketfd != -1) { close(socketfd); } exit(EXIT_SUCCESS); }
int update_backup_svrlist(void* owner, void* data) { int idx = sizeof(svr_proto_t); taomee::pack_h(login_switch_sendbuf, static_cast<uint16_t>(0), idx); taomee::pack_h(login_switch_sendbuf, MIN_BACKUP_SVR, idx); taomee::pack_h(login_switch_sendbuf, MAX_BACKUP_SVR, idx); taomee::pack_h(login_switch_sendbuf, static_cast<uint32_t>(0), idx); svr_proto_t* pkg = reinterpret_cast<svr_proto_t*>(login_switch_sendbuf); pkg->len = idx; if(switch_fd == -1) { //switch_fd = connect_to_svr(my_opt.master_ip, my_opt.master_port, 65535, 1); switch_fd = connect_to_service(my_opt.master_ser, 0, 65535, 1); } if(switch_fd == -1) { ADD_TIMER_EVENT(&get_backup_tmr, update_backup_svrlist, NULL, get_now_tv()->tv_sec + 60); return 0; } pkg->seq = (0xFFFF<< 16) | 0; pkg->cmd = SWITCH_GET_RANGED_SVR_LIST; pkg->ret = 0; pkg->id = 0; send_to_switch(NULL, login_switch_sendbuf, idx); //TRACE_LOG("update backup svrlist"); ADD_TIMER_EVENT(&get_backup_tmr, update_backup_svrlist, NULL, get_now_tv()->tv_sec + 60); return 0; }
NTSTATUS connect_to_ipc(struct net_context *c, struct cli_state **cli_ctx, struct sockaddr_storage *server_ss, const char *server_name) { return connect_to_service(c, cli_ctx, server_ss, server_name, "IPC$", "IPC"); }
static int rest_call(PROVISIONING_SERVICE_CLIENT_HANDLE prov_client, HTTP_CLIENT_REQUEST_TYPE operation, const char* registration_path, HTTP_HEADERS_HANDLE request_headers, const char* content) { int result; size_t content_len; HTTP_CLIENT_HANDLE http_client; if (content == NULL) { content_len = 0; } else { content_len = strlen(content); } http_client = connect_to_service(prov_client); if (http_client == NULL) { LogError("Failed connecting to service"); result = __FAILURE__; } else { result = 0; do { uhttp_client_dowork(http_client); if (prov_client->http_state == HTTP_STATE_CONNECTED) { if (uhttp_client_execute_request(http_client, operation, registration_path, request_headers, (unsigned char*)content, content_len, on_http_reply_recv, prov_client) != HTTP_CLIENT_OK) { LogError("Failure executing http request"); prov_client->http_state = HTTP_STATE_ERROR; result = __FAILURE__; } else { prov_client->http_state = HTTP_STATE_REQUEST_SENT; } } else if (prov_client->http_state == HTTP_STATE_REQUEST_RECV) { prov_client->http_state = HTTP_STATE_COMPLETE; } else if (prov_client->http_state == HTTP_STATE_ERROR) { result = __FAILURE__; LogError("HTTP error"); } } while (prov_client->http_state != HTTP_STATE_COMPLETE && prov_client->http_state != HTTP_STATE_ERROR); uhttp_client_close(http_client, NULL, NULL); uhttp_client_destroy(http_client); } prov_client->http_state = HTTP_STATE_DISCONNECTED; return result; }
void CMoleSendCard::sendCard(userid_t userid, const code_t &code) { std::map<uint32_t, std::vector<conf_t> >::iterator it; it = m_confs.find(code.province_code); if (it == m_confs.end()) return; time_t cur = time(0); for (uint32_t i = 0; i < (*it).second.size(); ++i) { if ((*it).second[i].city_code == 0 || (*it).second[i].city_code == code.city_code) { if (cur < (*it).second[i].begin || cur > (*it).second[i].end) { DEBUG_LOG("post card timeout uid:%u", userid); continue; } std::map<uint32_t, std::vector<std::set<uint32_t> > >::iterator its; its = m_flags.find(code.province_code); if (its == m_flags.end()) { ERROR_LOG("flags can't find code.province_code"); continue; } // 已经发过就不发了. if ((*its).second[i].find(userid) != (*its).second[i].end()) { DEBUG_LOG("is send uid = %u", userid); continue; } if (m_proxy_fd == -1) { DEBUG_LOG("m_proxy_fd == -1 connect_to_service"); m_proxy_fd = connect_to_service(config_get_strval("service_dbproxy"), 0, 65535, 1); } proto_head_t *ph = (proto_head_t *)((*it).second[i].buf); ph->len = (*it).second[i].proto_len; ph->id = userid; if (-1 == net_send(m_proxy_fd, (char*)ph, ph->len)) { ERROR_LOG("net_send error uid=%u", ph->id); } else { DEBUG_LOG("sendcard uid=%u", ph->id); (*its).second[i].insert(userid); } } } }
void gkr_operation_request (GkrOperation *op, DBusMessage *req) { g_return_if_fail (req); g_assert (op); if (!op->conn) op->conn = connect_to_service (); if (op->conn) { g_assert (!op->pending); if (!dbus_connection_send_with_reply (op->conn, req, &op->pending, -1)) g_return_if_reached (); } if (op->pending) { if (gkr_decode_is_keyring (dbus_message_get_path (req))) gkr_operation_set_keyring_hint (op); dbus_pending_call_set_notify (op->pending, on_pending_call_notify, gkr_operation_ref (op), gkr_operation_unref); } else { gkr_operation_complete_later (op, MATE_KEYRING_RESULT_IO_ERROR); } }
/**************************************************************************** connect to \\server\ipc$ ****************************************************************************/ NTSTATUS connect_to_ipc(struct cli_state **c, struct in_addr *server_ip, const char *server_name) { return connect_to_service(c, server_ip, server_name, "IPC$", "IPC"); }
int main(int argc, char **argv) { printf("%s: HelenOS IPC Naming Service\n", NAME); int rc = service_init(); if (rc != EOK) return rc; rc = clonable_init(); if (rc != EOK) return rc; rc = task_init(); if (rc != EOK) return rc; printf("%s: Accepting connections\n", NAME); while (true) { process_pending_conn(); process_pending_wait(); ipc_call_t call; ipc_callid_t callid = ipc_wait_for_call(&call); task_id_t id; sysarg_t retval; switch (IPC_GET_IMETHOD(call)) { case IPC_M_PHONE_HUNGUP: retval = ns_task_disconnect(&call); break; case IPC_M_CONNECT_TO_ME: /* * Server requests service registration. */ if (service_clonable(IPC_GET_ARG1(call))) { register_clonable(IPC_GET_ARG1(call), IPC_GET_ARG5(call), &call, callid); continue; } else { retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG5(call), &call); } break; case IPC_M_CONNECT_ME_TO: /* * Client requests to be connected to a service. */ if (service_clonable(IPC_GET_ARG1(call))) { connect_to_clonable(IPC_GET_ARG1(call), &call, callid); continue; } else { connect_to_service(IPC_GET_ARG1(call), &call, callid); continue; } break; case NS_PING: retval = EOK; break; case NS_TASK_WAIT: id = (task_id_t) MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); wait_for_task(id, &call, callid); continue; case NS_ID_INTRO: retval = ns_task_id_intro(&call); break; case NS_RETVAL: retval = ns_task_retval(&call); break; default: retval = ENOENT; break; } if (!(callid & IPC_CALLID_NOTIFICATION)) ipc_answer_0(callid, retval); } /* Not reached */ return 0; }