コード例 #1
0
/**
 **************************************************************************
 *
 * \brief Process the "show" command.
 *
 **************************************************************************
 */
static bool
ProcessCmdShow(int sd,        // IN
               char *data,    // IN
               int dataSize)  // IN
{
    MsgHdr req, reply;

    memset(&req, 0, sizeof req);
    req.type = MSG_SHOW;
    
    if (WriteFully(sd, &req, sizeof req) <= 0) {
        return false;
    }

    if (ReadFully(sd, &reply, sizeof reply) <= 0) {
        return false;
    }
    if (reply.type != MSG_BOARD) {
        Error("Unexpected reply message type %d\n", reply.type);
        return false;
    }

    while (reply.dataSize > 0) {
        char ch;
        if (ReadFully(sd, &ch, sizeof ch) <= 0) {
            return false;
        }
        printf("%c", ch);
        reply.dataSize--;
    }
    return false;
}
コード例 #2
0
/**
 **************************************************************************
 *
 * \brief Process the "post" command.
 *
 **************************************************************************
 */
static bool
ProcessCmdPost(int sd,        // IN
               char *data,    // IN
               int dataSize)  // IN
{
    MsgHdr req, reply;

    memset(&req, 0, sizeof req);
    req.type     = MSG_POST;
    req.dataSize = dataSize;
    
    if (WriteFully(sd, &req, sizeof req) <= 0) {
        return false;
    }
    if (WriteFully(sd, data, dataSize) <= 0) {
        return false;
    }

    if (ReadFully(sd, &reply, sizeof reply) <= 0) {
        return false;
    }
    if (reply.type != MSG_STATUS) {
        Error("Unexpected reply message type %d\n", reply.type);
        return false;
    }
    return false;
}
コード例 #3
0
void notifyHostBootComplete() {
   if (s_QemuMiscPipe < 0) {
        s_QemuMiscPipe = qemu_pipe_open(QEMU_MISC_PIPE);
        if (s_QemuMiscPipe < 0) {
            ALOGE("failed to open %s", QEMU_MISC_PIPE);
            return;
        }
    }
    char set[] = "bootcomplete";
    int pipe_command_length = sizeof(set);
    WriteFully(s_QemuMiscPipe, &pipe_command_length, sizeof(pipe_command_length));
    WriteFully(s_QemuMiscPipe, set, pipe_command_length);
    ReadFully(s_QemuMiscPipe, &pipe_command_length, sizeof(pipe_command_length));
    if (pipe_command_length > sizeof(set) || pipe_command_length <= 0)
        return;
    ReadFully(s_QemuMiscPipe, set, pipe_command_length);
}
コード例 #4
0
void CopyStream(PVOID p) {
	CopyThreadParams* data = (CopyThreadParams*)p;
	while (true) {
		DWORD len = 0;
		if (!ReadFully(data->hPipe,&len,sizeof(DWORD)))
			break;

		if (len==0)	break;	// EOF

		BYTE* buf = (BYTE*)malloc(len);
		if (!ReadFully(data->hPipe,buf,len))
			break;

		DWORD dwWritten;
		WriteFile(data->hStdin, buf, len, &dwWritten, NULL);
		free(buf);
		// repeeat
	}

	CloseHandle(data->hStdin);
	delete data;
	return;
}
コード例 #5
0
// Handles a client
void CommunicationPipeThreadProc( void* pParam )
{
   HANDLE hPipe = (HANDLE)pParam;

   RemComMessage msg;
   RemComResponse response;

   DWORD dwWritten;

   // Increment instance counter 
   InterlockedIncrement( &dwSvcPipeInstanceCount );

   ::ZeroMemory( &response, sizeof(response) );

   // Waiting for communication message from client
   if (!ReadFully( hPipe, &msg, sizeof(msg)))
	   goto cleanup;

   // Execute the requested command
   response.dwErrorCode  = Execute( hPipe, &msg, &response.dwReturnCode );
   
   // Send back the response message (client is waiting for this response)
   if ( !WriteFile( hPipe, &response, sizeof(response), &dwWritten, NULL ) || dwWritten == 0 )
      goto cleanup;

cleanup:

   // DisconnectNamedPipe( hPipe );
   CloseHandle( hPipe );

   // Decrement instance counter 
   InterlockedDecrement( &dwSvcPipeInstanceCount );

   // If this was the last client, let's stop ourself
   if ( dwSvcPipeInstanceCount == 0 )
      SetEvent( hStopServiceEvent );
     
}
コード例 #6
0
ファイル: protocol.hpp プロジェクト: losvald/jpgsync
 static inline bool ReadExactly(int fd, void* buf, size_t count) {
   return ReadFully(fd, buf, count) == count;
 }