PoolPtr initPool() { mysqlcpp::ConnectionPoolOpt pool_opt{}; pool_opt.m_thread_pool_size = POOL_SIZE; mysqlcpp::ConnectionOpt conn_opt = initConn(); auto pool = std::make_shared<mysqlcpp::ConnectionPool>(conn_opt, pool_opt); if (!pool->init()) { std::cout << "pool init fail\n"; return nullptr; } return pool; }
/* The following function writes the current log entry * to an established database connection. */ rsRetVal writeDB(uchar *psz, instanceData *pData) { DEFiRet; dbi_result dbiRes = NULL; ASSERT(psz != NULL); ASSERT(pData != NULL); /* see if we are ready to proceed */ if(pData->conn == NULL) { CHKiRet(initConn(pData, 0)); } /* try insert */ if((dbiRes = dbi_conn_query(pData->conn, (const char*)psz)) == NULL) { /* error occured, try to re-init connection and retry */ closeConn(pData); /* close the current handle */ CHKiRet(initConn(pData, 0)); /* try to re-open */ if((dbiRes = dbi_conn_query(pData->conn, (const char*)psz)) == NULL) { /* re-try insert */ /* we failed, giving up for now */ reportDBError(pData, 0); closeConn(pData); /* free ressources */ ABORT_FINALIZE(RS_RET_SUSPENDED); } } finalize_it: if(iRet == RS_RET_OK) { pData->uLastDBErrno = 0; /* reset error for error supression */ } if(dbiRes != NULL) dbi_result_free(dbiRes); RETiRet; }
int main(int argc, char **argv) { int fd; char cmd[1024]; if(argc < 2) { fprintf(stderr,"usage: %s <pdu data>\n",argv[0]); exit(1); } fd = initConn(115200); at(fd); sendStrCmd(fd, "AT+CMGF=0\r"); readResp(fd); sprintf(cmd, "AT+CMGS=%ld\r", strlen(argv[1])/2 - 1); sendStrCmd(fd, cmd); readResp(fd); sprintf(cmd,"%s\032",argv[1]); sendStrCmd(fd, cmd); readResp(fd); closeConn(fd); return 0; }
finalize_it: if(iRet == RS_RET_OK) { pData->uLastDBErrno = 0; /* reset error for error supression */ } if(dbiRes != NULL) dbi_result_free(dbiRes); RETiRet; } BEGINtryResume CODESTARTtryResume if(pData->conn == NULL) { iRet = initConn(pData, 1); } ENDtryResume /* transaction support 2013-03 */ BEGINbeginTransaction CODESTARTbeginTransaction if(pData->conn == NULL) { CHKiRet(initConn(pData, 0)); } # if HAVE_DBI_TXSUPP if (pData->txSupport == 1) { if (dbi_conn_transaction_begin(pData->conn) != 0) { dbgprintf("libdbi server error: begin transaction not successful\n"); iRet = RS_RET_SUSPENDED; }
finalize_it: if(iRet == RS_RET_OK) { pData->uLastDBErrno = 0; /* reset error for error supression */ } if(dbiRes != NULL) dbi_result_free(dbiRes); RETiRet; } BEGINtryResume CODESTARTtryResume if(pWrkrData->pData->conn == NULL) { iRet = initConn(pWrkrData->pData, 1); } ENDtryResume /* transaction support 2013-03 */ BEGINbeginTransaction CODESTARTbeginTransaction if(pWrkrData->pData->conn == NULL) { CHKiRet(initConn(pWrkrData->pData, 0)); } # if HAVE_DBI_TXSUPP if (pData->txSupport == 1) { if (dbi_conn_transaction_begin(pData->conn) != 0) { const char *emsg; dbi_conn_error(pData->conn, &emsg); dbgprintf("libdbi server error: begin transaction "
int main (int argc, char **argv) { irodsOper.getattr = irodsGetattr; irodsOper.readlink = irodsReadlink; irodsOper.readdir = irodsReaddir; irodsOper.mknod = irodsMknod; irodsOper.mkdir = irodsMkdir; irodsOper.symlink = irodsSymlink; irodsOper.unlink = irodsUnlink; irodsOper.rmdir = irodsRmdir; irodsOper.rename = irodsRename; irodsOper.link = irodsLink; irodsOper.chmod = irodsChmod; irodsOper.chown = irodsChown; irodsOper.truncate = irodsTruncate; irodsOper.utimens = irodsUtimens; irodsOper.open = irodsOpen; irodsOper.read = irodsRead; irodsOper.write = irodsWrite; irodsOper.statfs = irodsStatfs; irodsOper.release = irodsRelease; irodsOper.fsync = irodsFsync; irodsOper.flush = irodsFlush; int status; rodsArguments_t myRodsArgs; char *optStr; #ifdef __cplusplus bzero (&irodsOper, sizeof (irodsOper)); irodsOper.getattr = irodsGetattr; irodsOper.readlink = irodsReadlink; irodsOper.readdir = irodsReaddir; irodsOper.mknod = irodsMknod; irodsOper.mkdir = irodsMkdir; irodsOper.symlink = irodsSymlink; irodsOper.unlink = irodsUnlink; irodsOper.rmdir = irodsRmdir; irodsOper.rename = irodsRename; irodsOper.link = irodsLink; irodsOper.chmod = irodsChmod; irodsOper.chown = irodsChown; irodsOper.truncate = irodsTruncate; irodsOper.utimens = irodsUtimens; irodsOper.open = irodsOpen; irodsOper.read = irodsRead; irodsOper.write = irodsWrite; irodsOper.statfs = irodsStatfs; irodsOper.release = irodsRelease; irodsOper.fsync = irodsFsync; irodsOper.flush = irodsFlush; #endif optStr = "hdo:"; status = parseCmdLineOpt (argc, argv, optStr, 0, &myRodsArgs); if (status < 0) { printf("Use -h for help.\n"); exit (1); } if (myRodsArgs.help==True) { usage(); exit(0); } status = getRodsEnv (&MyRodsEnv); if (status < 0) { rodsLogError(LOG_ERROR, status, "main: getRodsEnv error. "); exit (1); } srandom((unsigned int) time(0) % getpid()); #ifdef CACHE_FILE_FOR_READ if (setAndMkFileCacheDir () < 0) exit (1); #endif initPathCache (); initIFuseDesc (); initConn(); initFileCache(); status = fuse_main (argc, argv, &irodsOper, NULL); disconnectAll (); if (status < 0) { exit (3); } else { exit(0); } }
/*function to drop packet*/ unsigned int handle_drop_packet(struct icpkthdr *header, short droptimes, struct connHashTable *table, int control_type, int pkt_type) { struct connectionInfo *Conn; struct pkt_control *pcon = NULL; unsigned int rnum; if (NULL == header) { return NF_ACCEPT; } /* if drop packets in a percentage, we do not need create connection */ if (percent > 0) { get_random_bytes(&rnum, sizeof(unsigned int)); if (rnum % 10000 < percent) return NF_DROP; return NF_ACCEPT; } /* find the packet in HashTable */ Conn = findInHT(header, table); if (Conn) { /* connection aready exsit */ switch (pkt_type) { case DATA_PACKET: case ACK_PACKET: pcon = Conn->pkt_control_info[pkt_type - 1]; if (pcon != NULL && (pcon->droptime[header->seq] > 0)) { /* decrease the drop times */ write_log("D/A", "DROP", droptimes - pcon->droptime[header->seq], header); pcon->droptime[header->seq]--; return NF_DROP; } else { write_log("D/A", "SKIP", droptimes - pcon->droptime[header->seq], header); return NF_ACCEPT; } break; case EOS_PACKET: if (Conn->eos_droptime > 0) { Conn->eos_droptime--; return NF_DROP; } else { return NF_ACCEPT; } break; default: return NF_ACCEPT; break; } } else { /* connection not exist */ /* use control type to init */ Conn = initConn(header, droptimes, control_type); /* create new connection */ if (NULL == Conn) { return NF_ACCEPT; } /* insert to the hash table */ if (0 == insertToHT(Conn, table)) { return NF_ACCEPT; } switch (pkt_type) { case DATA_PACKET: case ACK_PACKET: pcon = Conn->pkt_control_info[pkt_type - 1]; if (pcon != NULL && (pcon->droptime[header->seq] > 0)) { /* decrease the drop times */ write_log("D/A", "DROP", droptimes - pcon->droptime[header->seq], header); pcon->droptime[header->seq]--; return NF_DROP; } else { write_log("D/A", "SKIP", droptimes - pcon->droptime[header->seq], header); return NF_ACCEPT; } break; case EOS_PACKET: if (Conn->eos_droptime > 0) { Conn->eos_droptime--; return NF_DROP; } else { return NF_ACCEPT; } break; default: return NF_ACCEPT; break; } } }
int main (int argc, char **argv) { #ifdef ENABLE_TRACE irodsOper.getattr = traced_irodsGetattr; irodsOper.readlink = traced_irodsReadlink; irodsOper.readdir = traced_irodsReaddir; irodsOper.mknod = traced_irodsMknod; irodsOper.mkdir = traced_irodsMkdir; irodsOper.symlink = traced_irodsSymlink; irodsOper.unlink = traced_irodsUnlink; irodsOper.rmdir = traced_irodsRmdir; irodsOper.rename = traced_irodsRename; irodsOper.link = traced_irodsLink; irodsOper.chmod = traced_irodsChmod; irodsOper.chown = traced_irodsChown; irodsOper.truncate = traced_irodsTruncate; irodsOper.utimens = traced_irodsUtimens; irodsOper.open = traced_irodsOpen; irodsOper.read = traced_irodsRead; irodsOper.write = traced_irodsWrite; irodsOper.statfs = traced_irodsStatfs; irodsOper.release = traced_irodsRelease; irodsOper.fsync = traced_irodsFsync; irodsOper.flush = traced_irodsFlush; #else irodsOper.getattr = irodsGetattr; irodsOper.readlink = irodsReadlink; irodsOper.readdir = irodsReaddir; irodsOper.mknod = irodsMknod; irodsOper.mkdir = irodsMkdir; irodsOper.symlink = irodsSymlink; irodsOper.unlink = irodsUnlink; irodsOper.rmdir = irodsRmdir; irodsOper.rename = irodsRename; irodsOper.link = irodsLink; irodsOper.chmod = irodsChmod; irodsOper.chown = irodsChown; irodsOper.truncate = irodsTruncate; irodsOper.utimens = irodsUtimens; irodsOper.open = irodsOpen; irodsOper.read = irodsRead; irodsOper.write = irodsWrite; irodsOper.statfs = irodsStatfs; irodsOper.release = irodsRelease; irodsOper.fsync = irodsFsync; irodsOper.flush = irodsFlush; #endif // ENABLE_TRACE int status; rodsArguments_t myRodsArgs; char *optStr; int new_argc; char** new_argv; #ifdef __cplusplus #ifdef ENABLE_TRACE bzero (&irodsOper, sizeof (irodsOper)); irodsOper.getattr = traced_irodsGetattr; irodsOper.readlink = traced_irodsReadlink; irodsOper.readdir = traced_irodsReaddir; irodsOper.mknod = traced_irodsMknod; irodsOper.mkdir = traced_irodsMkdir; irodsOper.symlink = traced_irodsSymlink; irodsOper.unlink = traced_irodsUnlink; irodsOper.rmdir = traced_irodsRmdir; irodsOper.rename = traced_irodsRename; irodsOper.link = traced_irodsLink; irodsOper.chmod = traced_irodsChmod; irodsOper.chown = traced_irodsChown; irodsOper.truncate = traced_irodsTruncate; irodsOper.utimens = traced_irodsUtimens; irodsOper.open = traced_irodsOpen; irodsOper.read = traced_irodsRead; irodsOper.write = traced_irodsWrite; irodsOper.statfs = traced_irodsStatfs; irodsOper.release = traced_irodsRelease; irodsOper.fsync = traced_irodsFsync; irodsOper.flush = traced_irodsFlush; #else // no ENABLE_TRACE bzero (&irodsOper, sizeof (irodsOper)); irodsOper.getattr = irodsGetattr; irodsOper.readlink = irodsReadlink; irodsOper.readdir = irodsReaddir; irodsOper.mknod = irodsMknod; irodsOper.mkdir = irodsMkdir; irodsOper.symlink = irodsSymlink; irodsOper.unlink = irodsUnlink; irodsOper.rmdir = irodsRmdir; irodsOper.rename = irodsRename; irodsOper.link = irodsLink; irodsOper.chmod = irodsChmod; irodsOper.chown = irodsChown; irodsOper.truncate = irodsTruncate; irodsOper.utimens = irodsUtimens; irodsOper.open = irodsOpen; irodsOper.read = irodsRead; irodsOper.write = irodsWrite; irodsOper.statfs = irodsStatfs; irodsOper.release = irodsRelease; irodsOper.fsync = irodsFsync; irodsOper.flush = irodsFlush; #endif // ENABLE_TRACE #endif status = getRodsEnv (&MyRodsEnv); if (status < 0) { rodsLogError(LOG_ERROR, status, "main: getRodsEnv error. "); exit (1); } /* handle iRODS-FUSE specific command line options*/ status = parseFuseSpecificCmdLineOpt (argc, argv); if (status < 0) { printf("Use -h for help.\n"); exit (1); } status = makeCleanCmdLineOpt (argc, argv, &new_argc, &new_argv); argc = new_argc; argv = new_argv; optStr = "hdo:"; status = parseCmdLineOpt (argc, argv, optStr, 0, &myRodsArgs); if (status < 0) { printf("Use -h for help.\n"); exit (1); } if (myRodsArgs.help==True) { usage(); exit(0); } srandom((unsigned int) time(0) % getpid()); #ifdef CACHE_FILE_FOR_READ if (setAndMkFileCacheDir () < 0) exit (1); #endif initPathCache (); initIFuseDesc (); initConn(); initFileCache(); #ifdef ENABLE_PRELOAD // initialize preload initPreload (&MyPreloadConfig, &MyRodsEnv, &myRodsArgs); #endif #ifdef ENABLE_LAZY_UPLOAD // initialize Lazy Upload initLazyUpload (&MyLazyUploadConfig, &MyRodsEnv, &myRodsArgs); #endif #ifdef ENABLE_TRACE // start tracing status = trace_begin( NULL ); if( status != 0 ) { rodsLogError(LOG_ERROR, status, "main: trace_begin failed. "); exit(1); } #endif status = fuse_main (argc, argv, &irodsOper, NULL); #ifdef ENABLE_TRACE // stop tracing trace_end( NULL ); #endif /* release the preload command line options */ releaseCmdLineOpt (argc, argv); #ifdef ENABLE_PRELOAD // wait preload jobs waitPreloadJobs(); #endif #ifdef ENABLE_PRELOAD // uninitialize preload uninitPreload (&MyPreloadConfig); if (MyPreloadConfig.cachePath != NULL) { free(MyPreloadConfig.cachePath); } #endif #ifdef ENABLE_LAZY_UPLOAD // uninitialize lazy upload uninitLazyUpload (&MyLazyUploadConfig); if (MyLazyUploadConfig.bufferPath!=NULL) { free(MyLazyUploadConfig.bufferPath); } #endif disconnectAll (); if (status < 0) { exit (3); } else { exit(0); } }