static int contHandler(INKCont pCont, INKEvent event, void *edata) { INKHttpTxn pTxn = (INKHttpTxn) edata; switch (event) { case INK_EVENT_HTTP_TXN_START: handleTxnStart(pCont, pTxn); return 0; case INK_EVENT_HTTP_READ_REQUEST_HDR: handleReadRequest(pCont, pTxn); return 0; case INK_EVENT_HTTP_SEND_RESPONSE_HDR: handleSendResponse(pCont, pTxn); return 0; default: break; } return 0; }
// conn: fd for connection void handleDriverConnection(enum conn_type src_type){ struct fbs_header buffer; // Only for header struct fbs_request req; int off, bytesRead = 0; int status = 0; struct fbs_header header; struct pollfd fds[CONN_TYPE_LEN]; while (!eflag) { // printf("Thread: %d\n", src_type); while((status = cmgr->poll_conn(fds)) <= 0){ if (eflag || status < 0){ pthread_exit(0); } } if (fds[src_type].revents & (POLLHUP | POLLERR | POLLNVAL)){ cmgr->close(src_type); return; } if (!(fds[src_type].revents & POLLIN)){ continue; } if ((bytesRead = cmgr->recv_fr_cli(src_type, (char *)&buffer, sizeof(buffer))) <= 0){ if (bytesRead == 0){ printf("Socket closed by remote connection\n"); } else { perror("ERROR reading from socket"); } cmgr->close(src_type); return; } // Switch endianness req.command = ntohs(buffer.command); req.len = ntohl(buffer.len); req.offset = ntohl(buffer.offset); req.seq_num = ntohl(buffer.seq_num); req.req_num = ntohl(buffer.req_num); #ifdef DEBUG printf("Server req: %u %u %u %u %u\n", req.command, req.len, req.offset, req.seq_num, req.req_num); #endif switch (req.command){ case FBS_READ: status = handleReadRequest(src_type, req); break; case FBS_WRITE: status = handleWriteRequest(src_type, req); break; default: perror("ERROR Invalid command"); continue; } if (status < 0){ perror("ERROR handling request"); } } #ifdef DEBUG printf("Exiting handleDriverConnection\n"); #endif cmgr->close(src_type); return; }