/* Either file size was sent and now we send the file, or the file was sent and we delete the connection */ inline void FileServer::write_cb(struct bufferevent *bev, void *context) { try { auto u_ctx = static_cast<UploadContext*>(context); if(u_ctx->size_sent()) { LOG_DEBUG("File size was sent, sending file "); evbuffer_add_file(bufferevent_get_output(bev), u_ctx->fd(), 0, u_ctx->file()->size()); bufferevent_setwatermark(bev, EV_WRITE, 0, 0); u_ctx->size_sent(false); u_ctx->transfer_started(true); LOG_DEBUG("File transfer has started "); } else if(u_ctx->transfer_started()) { LOG_DEBUG("Transfer Completed"); FileServer * server = static_cast<FileServer*>(u_ctx->reader()); server->TransferDone(u_ctx); } } catch(std::exception& e) { LOG_ERR(e.what()); delete static_cast<ConnectionContext*>(context); exit(EXIT_FAILURE); } }