AsyncStatus asyncConnector_init(AsyncConnector* ac, const SockAddress* address, LoopIo* io) { int ret; ac->error = 0; ac->io = io; ret = socket_connect(io->fd, address); if (ret == 0) { ac->state = CONNECT_COMPLETED; return ASYNC_COMPLETE; } if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) { ac->state = CONNECT_CONNECTING; /* The socket will be marked writable for select() when the * connection is established, or when it is definitely * refused / timed-out, for any reason. */ loopIo_wantWrite(io); return ASYNC_NEED_MORE; } ac->error = errno; ac->state = CONNECT_ERROR; return ASYNC_ERROR; }
static void _adb_host_append_message(AdbHost* adb_host, const void* msg, int msglen) { printf("Append %d bytes to ADB host buffer.\n", msglen); /* Make sure that buffer can contain the appending data. */ if (adb_host->pending_send_buffer == NULL) { adb_host->pending_send_buffer = (uint8_t*)malloc(msglen); adb_host->pending_send_buffer_size = msglen; } else if ((adb_host->pending_send_data_size + msglen) > adb_host->pending_send_buffer_size) { adb_host->pending_send_buffer = (uint8_t*)realloc(adb_host->pending_send_buffer, adb_host->pending_send_data_size + msglen); adb_host->pending_send_buffer_size = adb_host->pending_send_data_size + msglen; } if (adb_host->pending_send_buffer == NULL) { D("Unable to allocate %d bytes for pending ADB host data.", adb_host->pending_send_data_size + msglen); adb_host->pending_send_buffer_size = adb_host->pending_send_data_size = 0; loopIo_dontWantWrite(adb_host->io); return; } memcpy(adb_host->pending_send_buffer + adb_host->pending_send_data_size, msg, msglen); loopIo_wantWrite(adb_host->io); }
void asyncWriter_init(AsyncWriter* aw, const void* buffer, size_t buffsize, LoopIo* io) { aw->buffer = buffer; aw->buffsize = buffsize; aw->pos = 0; aw->io = io; if (buffsize > 0) loopIo_wantWrite(io); }
static void netPipe_resetState( NetPipe* pipe ) { if ((pipe->wakeWanted & PIPE_WAKE_WRITE) != 0) { loopIo_wantWrite(pipe->io); } else { loopIo_dontWantWrite(pipe->io); } if (pipe->state == STATE_CONNECTED && (pipe->wakeWanted & PIPE_WAKE_READ) != 0) { loopIo_wantRead(pipe->io); } else { loopIo_dontWantRead(pipe->io); } }