/* Destroys AsyncSocketConnector instance.
 * Param:
 *  connector - Initialized AsyncSocketConnector instance.
 */
static void
_async_socket_connector_free(AsyncSocketConnector* connector)
{
    if (connector != NULL) {
        T("ASC %s: Connector is destroying...", _asc_socket_string(connector));

        /* Stop all activities. */
        if (asyncConnector_stop(connector->connector) == 0) {
            /* Connection was in progress. We need to destroy I/O descriptor for
             * that connection. */
            D("ASC %s: Stopped async connection in progress.",
              _asc_socket_string(connector));
            loopIo_done(connector->connector_io);
        }

        /* Free allocated resources. */
        if (connector->looper != NULL) {
            loopTimer_done(connector->connector_timer);
            if (connector->owns_looper) {
                looper_free(connector->looper);
            }
        }

        if (connector->fd >= 0) {
            socket_close(connector->fd);
        }

        T("ASC %s: Connector is destroyed", _asc_socket_string(connector));

        sock_address_done(&connector->address);

        AFREE(connector);
    }
}
예제 #2
0
void
userEventsImpl_destroy(void)
{
    if (_UserEventsImpl.looper != NULL) {
        // Stop all I/O that may still be going on.
        loopIo_done(&_UserEventsImpl.io);
        looper_free(_UserEventsImpl.looper);
        _UserEventsImpl.looper = NULL;
    }
}
예제 #3
0
void
attachUiProxy_destroy(void)
{
    if (_attachUiProxy.looper != NULL) {
        // Stop all I/O that may still be going on.
        loopIo_done(&_attachUiProxy.io);
        looper_free(_attachUiProxy.looper);
        _attachUiProxy.looper = NULL;
    }
    _attachUiProxy.sock = -1;
}
static void
netPipe_free( NetPipe*  pipe )
{
    int  fd;

    /* Close the socket */
    fd = pipe->io->fd;
    loopIo_done(pipe->io);
    socket_close(fd);

    /* Release the pipe object */
    AFREE(pipe);
}
/* Asynchronous connector (AsyncConnector instance) has completed connection
 *  attempt.
 * Param:
 *  connector - Initialized AsyncSocketConnector instance. Note: When this
 *      callback is called, the caller has referenced passed connector object,
 *      So, it's guaranteed that this connector is not going to be destroyed
 *      while this routine executes.
 *  status - Status of the connection attempt.
 */
static void
_on_async_socket_connector_connecting(AsyncSocketConnector* connector,
                                      AsyncStatus status)
{
    AsyncIOAction action = ASIO_ACTION_DONE;

    switch (status) {
        case ASYNC_COMPLETE:
            loopIo_done(connector->connector_io);
            D("Socket '%s' is connected", _asc_socket_string(connector));
            /* Invoke "on connected" callback */
            action = connector->on_connected_cb(connector->on_connected_cb_opaque,
                                                connector, ASIO_STATE_SUCCEEDED);
            break;

        case ASYNC_ERROR:
            loopIo_done(connector->connector_io);
            D("Error while connecting to socket '%s': %d -> %s",
              _asc_socket_string(connector), errno, strerror(errno));
            /* Invoke "on connected" callback */
            action = connector->on_connected_cb(connector->on_connected_cb_opaque,
                                                connector, ASIO_STATE_FAILED);
            break;

        case ASYNC_NEED_MORE:
            T("ASC %s: Waiting on connection to complete. Connector FD = %d",
              _asc_socket_string(connector), connector->fd);
            return;
    }

    if (action == ASIO_ACTION_RETRY) {
        D("ASC %s: Retrying connection. Connector FD = %d",
          _asc_socket_string(connector), connector->fd);
        loopTimer_startRelative(connector->connector_timer, connector->retry_to);
    } else if (action == ASIO_ACTION_ABORT) {
        D("ASC %s: Client has aborted connection. Connector FD = %d",
          _asc_socket_string(connector), connector->fd);
    }
}
void
uiCmdProxy_destroy()
{
    
    if (_uiCmdProxy.sync_writer != NULL) {
        syncsocket_close(_uiCmdProxy.sync_writer);
        syncsocket_free(_uiCmdProxy.sync_writer);
    }
    if (_uiCmdProxy.looper != NULL) {
        
        loopIo_done(&_uiCmdProxy.io);
        looper_free(_uiCmdProxy.looper);
        _uiCmdProxy.looper = NULL;
    }
    _uiCmdProxy.sock = -1;
}
예제 #7
0
DrainerObject::~DrainerObject() {
    if (!mSocketIsDrained) {
        char buff[1024];
        while(socket_recv(mSocket, buff, sizeof(buff)) > 0) { ; }
        mSocketIsDrained = true;
    }
    shutdownRead();
    if (mLooper) {
        loopIo_dontWantRead(mIo);
        loopIo_done(mIo);
        mLooper = 0;
    }
    closeSocket();
    mSocket = -1;
    mParent = 0;
}
void
coreCmdImpl_destroy()
{
    // Destroy the writer
    if (_coreCmdImpl.sync_writer != NULL) {
        syncsocket_close(_coreCmdImpl.sync_writer);
        syncsocket_free(_coreCmdImpl.sync_writer);
    }
    if (_coreCmdImpl.looper != NULL) {
        // Stop all I/O that may still be going on.
        loopIo_done(&_coreCmdImpl.io);
        looper_free(_coreCmdImpl.looper);
        _coreCmdImpl.looper = NULL;
    }
    // Free allocated memory.
    _free_cmd_param_buf(&_coreCmdImpl);
}
예제 #9
0
파일: adb-server.c 프로젝트: 3a9LL/panda
/* Frees AdbHost instance created with _adb_host_new routine. */
static void
_adb_host_free(AdbHost* adb_host)
{
    if (adb_host != NULL) {
        /* At this point it must not be listed anywhere. */
        assert(alist_is_empty(&adb_host->list_entry));

        /* Close the host socket. */
        if (adb_host->host_so >= 0) {
            loopIo_done(adb_host->io);
            socket_close(adb_host->host_so);
        }

        /* Free pending data buffers. */
        if (adb_host->pending_data != NULL) {
            free(adb_host->pending_data);
        }
        if (adb_host->pending_send_buffer != NULL) {
            free(adb_host->pending_send_buffer);
        }

        AFREE(adb_host);
    }
}
예제 #10
0
static void
coreconsole_done(CoreConsole* cc)
{
    socket_close(cc->io->fd);
    loopIo_done(cc->io);
}