/// (A)gent (S)erver read /// A wrapper of read(), performing additional socket connection check /// to ensure the communication between QEMU and the in-VM agent server /// /// \param sock_fd The file descriptor of socket /// \param buf Pointer to the buffer to be read /// \param count Count in bytes of buf to be read /// /// Return bytes read, <= 0 if any error occured static ssize_t _MOCKABLE(as_read)( int sock_fd, void* buf, size_t count ) { socklen_t length; ssize_t n_rbytes = recvfrom( sock_fd, buf, count, 0, (struct sockaddr*)&ac->serveraddr, &length ); // 0: connection orderly closed, -1: error if( n_rbytes <= 0 ) { agent_printf( "The connection to the agent server is broken while reading\n" ); agent_cleanup(); } return n_rbytes; }
/// (A)gent (S)erver write /// A wrapper of write(), performing additional socket connection check /// to ensure the communication between QEMU and the in-VM agent server /// /// \param sock_fd The file descriptor of socket /// \param buf Pointer to the buffer to be written /// \param count Count in bytes of buf to be written /// /// Return bytes written, <= 0 if any error occured static ssize_t _MOCKABLE(as_write)( int sock_fd, void* buf, size_t count ) { socklen_t length = sizeof(ac->serveraddr); ssize_t n_wbytes = sendto( sock_fd, buf, count, 0, (struct sockaddr*)&ac->serveraddr, length ); // 0: connection orderly closed, -1: error if( n_wbytes <= 0 ) { agent_printf( "The connection to the agent server is broken while writing\n" ); agent_cleanup(); } return n_wbytes; }
static void onAgentCleanup(int theConnection) { /* Read the data in the buffer (data from server) */ /* No data sent for agent cleanup */ /* Call RL method on the recv'd data */ agent_cleanup(); /* Prepare the buffer for sending data back to the server */ rlBufferClear(&theBuffer); /* Cleanup our resources */ clearRLStruct(&clientagent_observation); free(theTaskSpec); free(clientagent_inmessage); theTaskSpec = 0; clientagent_inmessage = 0; clientagent_inmessagecapacity = 0; }
MBA_AGENT_RETURN agent_reset( Monitor *mon ) { // Copy the previous fwd_port int fwd_port = ac->fwd_port; agent_cleanup(); return agent_init( mon, fwd_port, NULL ); }
void performCleanup() { agent_cleanup(); }