int ListenOn(Address &addr) { ENTER_LOG; fd_ = socket(AF_INET, SOCK_STREAM, 0); if (fd_ < 0) { FATAL_LOG("create socket error: %d %s", errno, strerror(errno)); LEAVE_ERR_LOG; return -1; } SetNonBlocking(fd_); if (bind(fd_, (struct sockaddr*)&addr.GetSockaddr(), sizeof(struct sockaddr_in)) < 0) { FATAL_LOG("bind error: %d %s", errno, strerror(errno)); close(fd_); LEAVE_ERR_LOG; return -3; } if (listen(fd_, 1024) < 0) { FATAL_LOG("listen error: %d %s", errno, strerror(errno)); close(fd_); LEAVE_ERR_LOG; return -4; } LEAVE_LOG; return 0; };
void check_is_template() { bool expected = Expected; using checker = is_template<TTemplates...>; bool actual = checker::template type<T>::value; if (expected != actual) { FATAL_LOG(ERROR) << "checker: " << type_str<checker>(); FATAL_LOG(ERROR) << "type: " << type_str<T>(); FATAL_EXPECT_EQ(expected, actual); } }
void ev_handler(int fd, short ev_flags, void *arg) { int n = 0; if(ev_flags & E_READ) { if( ( n = read(fd, buffer[fd], EV_BUF_SIZE)) > 0 ) { SHOW_LOG("Read %d bytes from %d", n, fd); buffer[fd][n] = 0; SHOW_LOG("Updating event[%x] on %d ", events[fd], fd); if(events[fd]) { events[fd]->add(events[fd], E_WRITE); } } else { if(n < 0 ) FATAL_LOG("Reading from %d failed, %s", fd, strerror(errno)); goto err; } } if(ev_flags & E_WRITE) { if( (n = write(fd, buffer[fd], strlen(buffer[fd])) ) > 0 ) { SHOW_LOG("Wrote %d bytes via %d", n, fd); } else { if(n < 0) FATAL_LOG("Wrote data via %d failed, %s", fd, strerror(errno)); goto err; } if(events[fd]) events[fd]->del(events[fd], E_WRITE); } return ; err: { if(events[fd]) { events[fd]->destroy(events[fd]); events[fd] = NULL; shutdown(fd, SHUT_RDWR); close(fd); SHOW_LOG("Connection %d closed", fd); } } }
void CheckIdleUserTask::destroy(MUTimer *pChannel) { m_pTimer = NULL; FATAL_LOG("Check idle user task, timer error"); }
int Ardb::BlockForKeys(Context& ctx, const StringArray& keys, const AnyArray& vals, KeyType ktype, uint32 mstimeout) { if (ctx.keyslocked) { FATAL_LOG("Can not modify block dataset when key locked."); } if (mstimeout > 0) { ctx.GetBPop().timeout = (uint64) mstimeout * 1000 + get_current_epoch_micros(); } ctx.GetBPop().block_keytype = ktype; ctx.client->client->BlockRead(); LockGuard<SpinMutexLock> guard(m_block_keys_lock); for (size_t i = 0; i < keys.size(); i++) { KeyPrefix prefix; prefix.ns = ctx.ns; prefix.key.SetString(keys[i], false); if(vals.size() != keys.size()) { ctx.GetBPop().keys.insert(BlockingState::BlockKeyTable::value_type(prefix, NULL)); }else { ctx.GetBPop().keys.insert(BlockingState::BlockKeyTable::value_type(prefix, vals[i])); } m_blocked_ctxs[prefix].insert(&ctx); } return 0; }
static void fromItemToSQL(StringInfo str, FromItem *f) { switch(f->type) { case T_FromTableRef: { FromTableRef *r = (FromTableRef *) f; appendStringInfo(str, "%s", r->tableId); } break; case T_FromSubquery: { FromSubquery *q = (FromSubquery *) f; appendStringInfoString(str, "("); nodeToSQL(str, q->subquery); appendStringInfoString(str, ")"); } break; default: FATAL_LOG("not supported yet: %u", f->type); } if (f->name) appendStringInfo(str, " %s", f->name); }
void LogFlushTask::destroy(MUTimer *pChannel) { m_pTimer = NULL; FATAL_LOG("log flush task, timer error"); recycle(); }
/* sock_dgram /UCP handler */ void ev_udp_handler(int fd, short ev_flags, void *arg) { int n = 0; struct sockaddr_in rsa; socklen_t rsa_len = sizeof(struct sockaddr); if(ev_flags & E_READ) { if( ( n = recvfrom(fd, conns[fd].response, EV_BUF_SIZE - 1, 0, (struct sockaddr *)&rsa, &rsa_len)) > 0 ) { SHOW_LOG("Read %d bytes from %d", n, fd); conns[fd].response[n] = 0; SHOW_LOG("Updating event[%p] on %d ", &conns[fd].event, fd); event_add(&conns[fd].event, E_WRITE); } else { if(n < 0 ) FATAL_LOG("Reading from %d failed, %s", fd, strerror(errno)); goto err; } } if(ev_flags & E_WRITE) { if( (n = write(fd, conns[fd].request, strlen(conns[fd].request)) ) > 0 ) { SHOW_LOG("Wrote %d bytes via %d", n, fd); } else { if(n < 0) FATAL_LOG("Wrote data via %d failed, %s", fd, strerror(errno)); goto err; } event_del(&conns[fd].event, E_WRITE); } return ; err: { event_destroy(&conns[fd].event); shutdown(fd, SHUT_RDWR); close(fd); SHOW_LOG("Connection %d closed", fd); } }
Node * postgresExecuteAsTransactionAndGetXID (List *statements, IsolationLevel isoLevel) { Constant *xid = NULL; FATAL_LOG("not supported for postgres yet"); return (Node *) xid; }
static ParserPlugin * assembleHivePlugin(void) { ParserPlugin *p = NEW(ParserPlugin); // p->parseStream = parseStreamHive; // p->parseFromString = parseFromStringHive; FATAL_LOG("not implemented yet"); return p; }
int Client::connect(const InetAddress& addr) { if (mEpoller == NULL || mLoop == NULL || mSock == NULL) { FATAL_LOG("new obj failed"); return false; } mEpoller->createEpoll(); mConnection = NEW Connection(mSock, mLoop); mEpoller->addRW(mConnection); return mSock->connect(addr); }
int main(){ Graph<int, int> g; FILE* fp = fopen("graph.db","r"); if(fp == NULL){ FATAL_LOG("fp is null"); } parseMatrix(g,fp); // debug<int, int>(g); g.show(); return 0; }
void LogDispatcher::rotateLog(uint64_t bucketId) { Bucket *pBucket = BucketManager::getInstance()->get(bucketId); if (NULL == pBucket) { FATAL_LOG("try to rotate log for bucket %" PRIu64 ", but it does not exist", bucketId); return ; } LogEvent event; event.m_BucketId = bucketId; event.m_UserId = UINT64_MAX; event.m_OpCode = MU_OP_ROTATE_LOG; event.m_SeqNr = ++(pBucket->m_LogSeq); cstore::Log_Entry entry; entry.set_seq_nr(event.m_SeqNr); entry.set_uid(event.m_UserId); entry.set_token(event.m_Token); entry.set_op_code(event.m_OpCode); if (!entry.SerializeToString(&(event.m_SerializedLog))) { ERROR_LOG("protobuf serialize failed"); FATAL_LOG("error occurred when we " "try to rotate log for bucket %" PRIu64, bucketId); return ; } LogThreadRequest *pReq = new LogThreadRequest(); pReq->m_OpType = LogThreadRequest::ROTATE_LOG; pReq->m_LogEvent = event; pReq->m_TotalBuckets = RuleManager::getInstance()->getTotalBuckets(); m_ReqList.push_back(pReq); // 打开线程池句柄写事件 m_WriteEpollEvent.openWevent(); }
/* function definitions */ Node * provRewriteQBModel (Node *qbModel) { if (isA(qbModel, List)) return (Node *) provRewriteQueryList((List *) qbModel); else if (IS_OP(qbModel)) return (Node *) provRewriteQuery((QueryOperator *) qbModel); FATAL_LOG("cannot rewrite node <%s>", nodeToString(qbModel)); return NULL; }
int main(int argc, char* argv[]) { Logger::set_fp_stream(Logger::debug, "./debug.log"); Logger::set_fp_stream(Logger::fatal, "./error.log"); Logger::set_fp_stream(Logger::warning, "./error.log"); Logger::set_fp_stream(Logger::notice, "./notice.log"); DEBUG_LOG("debug log message"); FATAL_LOG("fatal log message"); WARNING_LOG("warning log message"); NOTICE_LOG("notice log message"); STDERR_LOG("stderr log message"); STDOUT_LOG("stdout log message"); return 0; }
static void nodeToSQL(StringInfo str, Node *node) { switch(node->type) { case T_QueryBlock: blockToSQL(str, (QueryBlock *) node); break; case T_SetQuery: setToSQL(str, (SetQuery *) node); break; default: FATAL_LOG("node type not supports: %u", node->type); } }
void chooseParserPluginFromString(char *type) { INFO_LOG("PLUGIN parser: <%s>", type); if (streq(type,"oracle")) chooseParserPlugin(PARSER_PLUGIN_ORACLE); else if (streq(type,"postgres")) chooseParserPlugin(PARSER_PLUGIN_POSTGRES); else if (streq(type,"hive")) chooseParserPlugin(PARSER_PLUGIN_HIVE); else if (streq(type,"dl")) chooseParserPlugin(PARSER_PLUGIN_DL); else FATAL_LOG("unkown parser plugin type: <%s>", type); }
int postgresDatabaseConnectionOpen (void) { StringInfo connStr = makeStringInfo(); // OptionConnection *op = getOptions()->optionConnection; ACQUIRE_MEM_CONTEXT(memContext); /* create connection string */ // if (op->host) appendStringInfo(connStr, " host=%s", getStringOption("connection.host")); // if (op->db) appendStringInfo(connStr, " dbname=%s", getStringOption("connection.db")); // if (op->user) appendStringInfo(connStr, " user=%s", getStringOption("connection.user")); if (optionSet("connection.passwd")) appendStringInfo(connStr, " password=%s", getStringOption("connection.passwd")); // if (op->port) appendStringInfo(connStr, " port=%u", getIntOption("connection.port")); /* try to connect to db */ plugin->conn = PQconnectdb(connStr->data); /* check to see that the backend connection was successfully made */ if (plugin->conn == NULL || PQstatus(plugin->conn) == CONNECTION_BAD) { char *error = PQerrorMessage(plugin->conn); PQfinish(plugin->conn); FATAL_LOG("unable to connect to postgres database %s\n\nfailed " "because of:\n%s", connStr->data, error); } plugin->initialized = TRUE; // prepare queries prepareLookupQueries(); // initialize cache fillOidToDTMap(GET_CACHE()->oidToDT); RELEASE_MEM_CONTEXT(); return EXIT_SUCCESS; }
int Ardb::UnblockKeys(Context& ctx, bool sync, RedisReply* reply) { if (ctx.keyslocked) { FATAL_LOG("Can not modify block dataset when key locked."); } if (!sync) { ctx.client->client->GetService().AsyncIO(ctx.client->client->GetID(), AsyncUnblockKeysCallback, new ContexWithReply(&ctx, reply)); return 0; } if (NULL != reply) { Channel* ch = ctx.client->client; ch->Write(*reply); } LockGuard<SpinMutexLock> guard(m_block_keys_lock, true); if (ctx.bpop != NULL && !m_blocked_ctxs.empty()) { BlockingState::BlockKeyTable::iterator it = ctx.GetBPop().keys.begin(); while (it != ctx.GetBPop().keys.end()) { const KeyPrefix& prefix = it->first; BlockedContextTable::iterator blocked_found = m_blocked_ctxs.find(prefix); if (blocked_found != m_blocked_ctxs.end()) { ContextSet& blocked_set = blocked_found->second; blocked_set.erase(&ctx); if (blocked_set.empty()) { m_blocked_ctxs.erase(blocked_found); } } it++; } ctx.ClearBPop(); } ctx.client->client->UnblockRead(); return 0; }
Node * rewriteForGP(Node *input) { if (isA(input, DLProgram)) { DLProgram *p = (DLProgram *) input; if (IS_GP_PROV(p)) { p = createBottomUpGPprogram(p); //TODO TopDown decide based on option } INFO_LOG("program for compute GP is:\n%s", datalogToOverviewString((Node *) p)); return (Node *) p; } else FATAL_LOG("currently only GP computation for DLPrograms supported."); return input; }
int Ardb::SignalKeyAsReady(Context& ctx, const std::string& key) { if (ctx.keyslocked) { FATAL_LOG("Can not modify block dataset when key locked."); } LockGuard<SpinMutexLock> guard(m_block_keys_lock, !ctx.flags.block_keys_locked); KeyPrefix prefix; prefix.ns = ctx.ns; prefix.key.SetString(key, false); if (m_blocked_ctxs.find(prefix) == m_blocked_ctxs.end()) { return -1; } if (NULL == m_ready_keys) { NEW(m_ready_keys, ReadyKeySet); } m_ready_keys->insert(prefix); return 0; }
/* sock_dgram /UCP handler */ void ev_udp_handler(int fd, int ev_flags, void *arg) { int i = 0, n = 0, nevdnsbuf = 0, reqfd = -1, respfd = -1; unsigned char evdnsbuf[EVDNS_BUF_SIZE], *p = NULL; char ip[DNS_IP_MAX]; HOSTENT hostent = {0}; if(ev_flags & E_READ) { //if( ( n = recvfrom(fd, buffer[fd], EV_BUF_SIZE, 0, (struct sockaddr *)&rsa, &rsa_len)) > 0 ) if( ( n = read(fd, buffer[fd], EV_BUF_SIZE)) > 0 ) { TIMER_SAMPLE(timer); evdns_parse_reply((unsigned char *)buffer[fd], n, &hostent); if(hostent.naddrs > 0) { fprintf(stdout, "time:%lld QID:%d name:%s nalias:%d naddrs:%d\n", PT_LU_USEC(timer), hostent.qid, hostent.name, hostent.nalias, hostent.naddrs); for(i = 0; i < hostent.nalias; i++) { fprintf(stdout, "alias%d:%s\n", i, hostent.alias[i]); } for(i = 0; i < hostent.naddrs; i++) { p = (unsigned char *)&(hostent.addrs[i]); sprintf(ip, "%d.%d.%d.%d", *p, *(p+1), *(p+2), *(p+3)); fprintf(stdout, "ip[%d] [%d][%s:][%d]\n", i, hostent.addrs[i], ip, inet_addr(ip)); } fprintf(stdout, "\r\n"); } if((respfd = open("/tmp/dns.response", O_CREAT|O_RDWR, 0644)) > 0) { if(write(respfd, buffer[fd], n) <= 0)_exit(-1); close(respfd); respfd = -1; _exit(-1); } SHOW_LOG("Read %d bytes from %d", n, fd); buffer[fd][n] = 0; SHOW_LOG("Updating event[%p] on %d ", &events[fd], fd); event_add(&events[fd], E_WRITE); } else { if(n < 0 ) FATAL_LOG("Reading from %d failed, %s", fd, strerror(errno)); goto err; } } if(ev_flags & E_WRITE) { nevdnsbuf = evdns_make_query(domain, 1, 1, 1, 1, evdnsbuf); if((reqfd = open("/tmp/dns.query", O_CREAT|O_RDWR, 0644)) > 0) { if(write(reqfd, evdnsbuf, nevdnsbuf) <= 0)_exit(-1); close(reqfd); reqfd = -1; } //if( (n = write(fd, buffer[fd], strlen(buffer[fd])) ) > 0 ) if((n = write(fd, evdnsbuf, nevdnsbuf)) > 0) { SHOW_LOG("Wrote %d bytes via %d", n, fd); TIMER_RESET(timer); } else { if(n < 0) FATAL_LOG("Wrote data via %d failed, %s", fd, strerror(errno)); goto err; } event_del(&events[fd], E_WRITE); } return ; err: { event_destroy(&events[fd]); shutdown(fd, SHUT_RDWR); close(fd); SHOW_LOG("Connection %d closed", fd); } }
/* sock stream/TCP handler */ void ev_handler(int fd, short ev_flags, void *arg) { int n = 0; if(ev_flags & E_READ) { if(is_use_ssl) { #ifdef USE_SSL n = SSL_read(conns[fd].ssl, conns[fd].response, EV_BUF_SIZE - 1); #else n = read(fd, conns[fd].response, EV_BUF_SIZE - 1); #endif } else { n = read(fd, conns[fd].response, EV_BUF_SIZE - 1); } if(n > 0 ) { SHOW_LOG("Read %d bytes from %d", n, fd); conns[fd].response[n] = 0; SHOW_LOG("Updating event[%p] on %d ", &conns[fd].event, fd); event_add(&conns[fd].event, E_WRITE); } else { if(n < 0 ) FATAL_LOG("Reading from %d failed, %s", fd, strerror(errno)); goto err; } } if(ev_flags & E_WRITE) { if(is_use_ssl) { #ifdef USE_SSL n = SSL_write(conns[fd].ssl, conns[fd].request, strlen(conns[fd].request)); #else n = write(fd, conns[fd].request, strlen(conns[fd].request)); #endif } else { n = write(fd, conns[fd].request, strlen(conns[fd].request)); } if(n > 0 ) { SHOW_LOG("Wrote %d bytes via %d", n, fd); } else { if(n < 0) FATAL_LOG("Wrote data via %d failed, %s", fd, strerror(errno)); goto err; } event_del(&conns[fd].event, E_WRITE); } return ; err: { event_destroy(&conns[fd].event); shutdown(fd, SHUT_RDWR); close(fd); #ifdef USE_SSL if(conns[fd].ssl) { SSL_shutdown(conns[fd].ssl); SSL_free(conns[fd].ssl); conns[fd].ssl = NULL; } #endif SHOW_LOG("Connection %d closed", fd); } }
int main(int argc, char **argv) { char *ip = NULL; int port = 0; int fd = 0; struct sockaddr_in sa, lsa; socklen_t sa_len, lsa_len = -1; int sock_type = 0; if(argc < 5) { fprintf(stderr, "Usage:%s sock_type(0/TCP|1/UDP) ip port domain\n", argv[0]); _exit(-1); } ev_sock_type = atoi(argv[1]); if(ev_sock_type < 0 || ev_sock_type > ev_sock_count) { fprintf(stderr, "sock_type must be 0/TCP OR 1/UDP\n"); _exit(-1); } sock_type = ev_sock_list[ev_sock_type]; ip = argv[2]; port = atoi(argv[3]); domain = argv[4]; /* Set resource limit */ setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, CONN_MAX); /* Initialize global vars */ memset(events, 0, sizeof(EVENT) * CONN_MAX); /* Initialize inet */ memset(&sa, 0, sizeof(struct sockaddr_in)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(ip); sa.sin_port = htons(port); sa_len = sizeof(struct sockaddr); /* set evbase */ if((evbase = evbase_init(0))) { TIMER_INIT(timer); //evbase->set_evops(evbase, EOP_POLL); if((fd = socket(AF_INET, sock_type, 0)) > 0) { /* Connect */ if(connect(fd, (struct sockaddr *)&sa, sa_len) == 0 ) { /* set FD NON-BLOCK */ fcntl(fd, F_SETFL, O_NONBLOCK); if(sock_type == SOCK_STREAM) { event_set(&events[fd], fd, E_READ|E_WRITE|E_PERSIST, (void *)&events[fd], &ev_handler); } else { event_set(&events[fd], fd, E_READ|E_WRITE|E_PERSIST, (void *)&events[fd], &ev_udp_handler); } evbase->add(evbase, &events[fd]); sprintf(buffer[fd], "%d:client message\r\n", fd); lsa_len = sizeof(struct sockaddr); memset(&lsa, 0, lsa_len); getsockname(fd, (struct sockaddr *)&lsa, &lsa_len); SHOW_LOG("Connected to %s:%d via %d port:%d", ip, port, fd, ntohs(lsa.sin_port)); } else { FATAL_LOG("Connect to %s:%d failed, %s", ip, port, strerror(errno)); _exit(-1); } } while(1) { evbase->loop(evbase, 0, NULL); usleep(10); } //TIMER_CLEAN(timer); } return -1; }
/* sock stream/TCP handler */ void ev_handler(int fd, int ev_flags, void *arg) { int n = 0, nevdnsbuf = 0, reqfd = -1, respfd = -1; unsigned char evdnsbuf[EVDNS_BUF_SIZE]; if(ev_flags & E_READ) { if( ( n = read(fd, buffer[fd], EV_BUF_SIZE)) > 0 ) { if((respfd = open("/tmp/dns.response", O_CREAT|O_RDWR, 0644)) > 0) { if(write(respfd, buffer[fd], n) <= 0)_exit(-1); close(respfd); respfd = -1; _exit(-1); } SHOW_LOG("Read %d bytes from %d", n, fd); buffer[fd][n] = 0; SHOW_LOG("Updating event[%p] on %d ", &events[fd], fd); event_add(&events[fd], E_WRITE); } else { if(n < 0 ) FATAL_LOG("Reading from %d failed, %s", fd, strerror(errno)); goto err; } } if(ev_flags & E_WRITE) { nevdnsbuf = evdns_make_query(domain, 1, 1, 0, 0, evdnsbuf); if((reqfd = open("/tmp/dns.query", O_CREAT|O_RDWR, 0644)) > 0) { if(write(reqfd, evdnsbuf, nevdnsbuf) <= 0) _exit(-1); close(reqfd); reqfd = -1; } //if((n = write(fd, buffer[fd], strlen(buffer[fd])) ) > 0 ) if((n = write(fd, evdnsbuf, nevdnsbuf)) > 0) { SHOW_LOG("Wrote %d bytes via %d", n, fd); } else { if(n < 0) FATAL_LOG("Wrote data via %d failed, %s", fd, strerror(errno)); goto err; } event_del(&events[fd], E_WRITE); } return ; err: { event_destroy(&events[fd]); shutdown(fd, SHUT_RDWR); close(fd); SHOW_LOG("Connection %d closed", fd); } }
int postgresGetCostEstimation(char *query) { FATAL_LOG("not supported yet"); return 0; }
int main(int argc, char **argv) { char *ip = NULL; int port = 0; int fd = 0; struct sockaddr_in sa, lsa; socklen_t sa_len, lsa_len = -1; int opt = 1; int i = 0; int conn_num = 0; EVENT *event = NULL; if(argc < 4) { fprintf(stderr, "Usage:%s ip port connection_number\n", argv[0]); _exit(-1); } ip = argv[1]; port = atoi(argv[2]); conn_num = atoi(argv[3]); /* Set resource limit */ setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, CONN_MAX); /* Initialize global vars */ memset(events, 0, sizeof(EVENT *) * CONN_MAX); /* Initialize inet */ memset(&sa, 0, sizeof(struct sockaddr_in)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(ip); sa.sin_port = htons(port); sa_len = sizeof(struct sockaddr); /* set evbase */ if((evbase = evbase_init(0))) { LOGGER_INIT(evbase->logger, "/tmp/ev_client.log"); evbase->set_evops(evbase, EOP_SELECT); while((fd = socket(AF_INET, SOCK_STREAM, 0)) > 0 && fd < conn_num) { /* Connect */ if(connect(fd, (struct sockaddr *)&sa, sa_len) == 0 ) { /* set FD NON-BLOCK */ fcntl(fd, F_SETFL, O_NONBLOCK); if((events[fd] = ev_init())) { events[fd]->set(events[fd], fd, E_READ|E_WRITE|E_PERSIST, (void *)events[fd], &ev_handler); evbase->add(evbase, events[fd]); sprintf(buffer[fd], "%d:client message", fd); } lsa_len = sizeof(struct sockaddr_in); memset(&lsa, 0, lsa_len); getsockname(fd, (struct sockaddr *)&lsa, &lsa_len); SHOW_LOG("Connected to %s:%d via %d port:%d", ip, port, fd, ntohs(lsa.sin_port)); } else { FATAL_LOG("Connect to %s:%d failed, %s", ip, port, strerror(errno)); break; } } while(1) { evbase->loop(evbase, 0, NULL); usleep(10); } } }
int main(int argc, char **argv) { char *ip = NULL; int port = 0; int fd = 0; struct sockaddr_in sa, lsa; socklen_t sa_len, lsa_len = -1; int i = 0; int conn_num = 0; int sock_type = 0; int flag = 0; if(argc < 5) { fprintf(stderr, "Usage:%s sock_type(0/TCP|1/UDP) ip port connection_number\n", argv[0]); _exit(-1); } ev_sock_type = atoi(argv[1]); if(ev_sock_type < 0 || ev_sock_type > ev_sock_count) { fprintf(stderr, "sock_type must be 0/TCP OR 1/UDP\n"); _exit(-1); } sock_type = ev_sock_list[ev_sock_type]; ip = argv[2]; port = atoi(argv[3]); conn_num = atoi(argv[4]); /* Set resource limit */ setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, CONN_MAX); /* Initialize global vars */ if((conns = (CONN *)calloc(CONN_MAX, sizeof(CONN)))) { //memset(events, 0, sizeof(EVENT *) * CONN_MAX); /* Initialize inet */ memset(&sa, 0, sizeof(struct sockaddr_in)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(ip); sa.sin_port = htons(port); sa_len = sizeof(struct sockaddr); /* set evbase */ if((evbase = evbase_init(0))) { LOGGER_INIT(evbase->logger, "/tmp/ev_client.log"); #ifdef USE_SSL SSL_library_init(); OpenSSL_add_all_algorithms(); SSL_load_error_strings(); if((ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) { ERR_print_errors_fp(stdout); _exit(-1); } #endif //evbase->set_evops(evbase, EOP_POLL); while((fd = socket(AF_INET, sock_type, 0)) > 0 && i < conn_num) { conns[fd].fd = fd; /* Connect */ if(connect(fd, (struct sockaddr *)&sa, sa_len) != 0) { FATAL_LOG("Connect to %s:%d failed, %s", ip, port, strerror(errno)); break; } if(is_use_ssl && sock_type == SOCK_STREAM) { #ifdef USE_SSL conns[fd].ssl = SSL_new(ctx); if(conns[fd].ssl == NULL ) { FATAL_LOG("new SSL with created CTX failed:%s\n", ERR_reason_error_string(ERR_get_error())); break; } if((ret = SSL_set_fd(conns[fd].ssl, fd)) == 0) { FATAL_LOG("add SSL to tcp socket failed:%s\n", ERR_reason_error_string(ERR_get_error())); break; } /* SSL Connect */ if(SSL_connect(conns[fd].ssl) < 0) { FATAL_LOG("SSL connection failed:%s\n", ERR_reason_error_string(ERR_get_error())); break; } #endif } /* set FD NON-BLOCK */ flag = fcntl(fd, F_GETFL, 0); flag |= O_NONBLOCK; fcntl(fd, F_SETFL, flag); if(sock_type == SOCK_STREAM) { event_set(&conns[fd].event, fd, E_READ|E_WRITE|E_PERSIST, (void *)&conns[fd].event, &ev_handler); } else { event_set(&conns[fd].event, fd, E_READ|E_WRITE|E_PERSIST, (void *)&conns[fd].event, &ev_udp_handler); } evbase->add(evbase, &conns[fd].event); sprintf(conns[fd].request, "GET / HTTP/1.0\r\n\r\n"); lsa_len = sizeof(struct sockaddr); memset(&lsa, 0, lsa_len); getsockname(fd, (struct sockaddr *)&lsa, &lsa_len); SHOW_LOG("%d:Connected to %s:%d via %d port:%d", i, ip, port, fd, ntohs(lsa.sin_port)); i++; } while(1) { evbase->loop(evbase, 0, NULL); usleep(1000); } for(i = 0; i < CONN_MAX; i++) { shutdown(conns[i].fd, SHUT_RDWR); close(conns[i].fd); event_destroy(&conns[i].event); #ifdef USE_SSL if(conns[i].ssl) { SSL_shutdown(conns[i].ssl); SSL_free(conns[i].ssl); } #endif } #ifdef USE_SSL ERR_free_strings(); SSL_CTX_free(ctx); #endif } free(conns); } return -1; }
int compare_keys(const char* k1, size_t k1_len, const char* k2, size_t k2_len, bool has_ns) { int ret = (NULL != k2) - (NULL != k1); if (0 != ret) { return ret; } Buffer kbuf1(const_cast<char*>(k1), 0, k1_len); Buffer kbuf2(const_cast<char*>(k2), 0, k2_len); KeyObject key1, key2; if (has_ns) { /* * 1. compare namespace */ if (!key1.DecodeNS(kbuf1, false)) { FATAL_LOG("Decode first key namespace failed in comparator."); } if (!key2.DecodeNS(kbuf2, false)) { FATAL_LOG("Decode second key namespace failed in comparator."); } ret = key1.GetNameSpace().Compare(key2.GetNameSpace(), false); if (ret != 0) { return ret; } } /* * 2. decode prefix */ if (!key1.DecodeKey(kbuf1, false)) { FATAL_LOG("Decode first key prefix failed in comparator. "); } if (!key2.DecodeKey(kbuf2, false)) { FATAL_LOG("Decode second key prefix failed in comparator. "); } /* * 3. compare key & type */ ret = key1.GetKey().Compare(key2.GetKey(), true); if (ret != 0) { return ret; } ret = (int) key1.DecodeType(kbuf1) - (int) key2.DecodeType(kbuf2); if (ret != 0) { return ret; } ret = key1.GetType() - key2.GetType(); if (ret != 0) { return ret; } // if(key1.GetType() == KEY_ANY || key2.GetType() == KEY_ANY) // { // return 0; // } /* * 4. only meta key has no element in key part */ uint8_t type = key1.GetType(); if (type != KEY_META) { int elen1 = key1.DecodeElementLength(kbuf1); int elen2 = key2.DecodeElementLength(kbuf2); if (elen1 < 0 || elen2 < 0) { FATAL_LOG("Invalid element length"); } ret = elen1 - elen2; if (ret != 0) { return ret; } for (int i = 0; i < elen1; i++) { if (!key1.DecodeElement(kbuf1, false, i)) { FATAL_LOG("Decode first key element:%u failed.", i); } if (!key2.DecodeElement(kbuf2, false, i)) { FATAL_LOG("Decode second key element:%u failed.", i); } ret = key1.GetElement(i).Compare(key2.GetElement(i), false); if (ret != 0) { return ret; } } } return ret; }
void postgresGetTransactionSQLAndSCNs (char *xid, List **scns, List **sqls, List **sqlBinds, IsolationLevel *iso, Constant *commitScn) { FATAL_LOG("not supported for postgres yet"); }