* Client thread function * * Thread function that is called when starting a new thread. * The DB/mysql is initialized for each thread. * * @param [in] arg Pointer to the BMPServer ClientInfo */
| 72 | * @param [in] arg Pointer to the BMPServer ClientInfo |
| 73 | */ |
| 74 | void *ClientThread(void *arg) { |
| 75 | // Setup the args |
| 76 | ThreadMgmt *thr = static_cast<ThreadMgmt *>(arg); |
| 77 | Logger *logger = thr->log; |
| 78 | |
| 79 | // Setup the client thread info struct |
| 80 | ClientThreadInfo cInfo; |
| 81 | cInfo.mbus = NULL; |
| 82 | cInfo.client = &thr->client; |
| 83 | cInfo.log = thr->log; |
| 84 | cInfo.closing = false; |
| 85 | |
| 86 | int sock_fds[2]; |
| 87 | pollfd pfd; |
| 88 | unsigned char *sock_buf = NULL; |
| 89 | |
| 90 | /* |
| 91 | * Setup the cleanup routine for when the thread is canceled. |
| 92 | * A thread is only canceled if openbmpd is terminated. |
| 93 | */ |
| 94 | pthread_cleanup_push(ClientThread_cancel, &cInfo); |
| 95 | |
| 96 | try { |
| 97 | // connect to message bus |
| 98 | cInfo.mbus = new msgBus_kafka(logger, thr->cfg, thr->cfg->c_hash_id); |
| 99 | |
| 100 | if (thr->cfg->debug_msgbus) |
| 101 | cInfo.mbus->enableDebug(); |
| 102 | |
| 103 | BMPReader rBMP(logger, thr->cfg); |
| 104 | LOG_INFO("Thread started to monitor BMP from router %s using socket %d buffer in bytes = %u", |
| 105 | cInfo.client->c_ip, cInfo.client->c_sock, thr->cfg->bmp_buffer_size); |
| 106 | |
| 107 | // Buffer client socket using pipe |
| 108 | socketpair(PF_LOCAL, SOCK_STREAM, 0, sock_fds); |
| 109 | cInfo.bmp_write_end_sock = sock_fds[1]; |
| 110 | cInfo.client->pipe_sock = sock_fds[0]; |
| 111 | |
| 112 | /* |
| 113 | * Create and start the reader thread to monitor the pipe fd (read end) |
| 114 | */ |
| 115 | bool bmp_run = true; |
| 116 | //cInfo.bmp_reader_thread = new std::thread([&] {rBMP.readerThreadLoop(bmp_run,cInfo.client, |
| 117 | cInfo.bmp_reader_thread = new std::thread(&BMPReader::readerThreadLoop, &rBMP, std::ref(bmp_run), cInfo.client, |
| 118 | (MsgBusInterface *)cInfo.mbus ); |
| 119 | |
| 120 | // Variables to handle circular buffer |
| 121 | sock_buf = new unsigned char[thr->cfg->bmp_buffer_size]; |
| 122 | int bytes_read = 0; |
| 123 | int write_buf_pos = 0; |
| 124 | int read_buf_pos = 0; |
| 125 | bool wrap_state = false; |
| 126 | unsigned char *sock_buf_read_ptr = sock_buf; |
| 127 | unsigned char *sock_buf_write_ptr = sock_buf; |
| 128 | |
| 129 | /* |
| 130 | * monitor and buffer the client socket |
| 131 | */ |
nothing calls this directly
no test coverage detected