/**
 * See pcsl_socket.h for definition.
 *
 * Note that this function NEVER returns PCSL_NET_WOULDBLOCK. Therefore, the
 * finish() function should never be called and does nothing.
 */
int pcsl_socket_close_start(
    void *handle,
    void **pContext)
{
    int status;
    int fd = na_get_fd(handle);
    /*
     * DEBUG:
     * printf("closing fd: %d\n", fd);
     */

    status = close(fd);
    lastError = errno;

    /*
     * If PCSL_NET_WOULDBLOCk is detected, the notification adapter must not be
     * destroyed.
     */
    na_destroy(handle);

    if (status == 0) {
        return PCSL_NET_SUCCESS;
    }

    return PCSL_NET_IOERROR;
}
/**
 * See pcsl_socket.h for definition.
 */
int pcsl_socket_open_finish(
    void *handle,
    void *context)
{
    int err;
    socklen_t err_size = sizeof(err);

    int fd = na_get_fd(handle);

    int status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &err_size);
    /*
     * DEBUG:
     * printf( "pcsl_socket_open_finish::handle=%d err=%d\n", fd, err);
     */

    lastError = err;

    if (err == 0) {
        na_unregister_for_write(handle);
        /*
         * DEBUG:
         * printf("opened fd: %d\n", fd);
         */
        return PCSL_NET_SUCCESS;
    } else {
        na_destroy(handle);
        close(fd);
        return PCSL_NET_IOERROR;
    }
}
Esempio n. 3
0
/**
 * See pcsl_datagram.h for definition.
 *
 * Note that this function NEVER returns PCSL_NET_WOULDBLOCK. Therefore, the 
 * finish() function should never be called and does nothing.
 */
int pcsl_datagram_close_start(
    void *handle,
    void **pContext)
{
    int status;
    int fd = na_get_fd(handle);
    /* printf("closing fd: %d\n", fd); */

    (void)pContext;
    na_destroy(handle);
    status = close(fd);
    lastError = errno;

    if (status == 0) {
        return PCSL_NET_SUCCESS;
    } 

    return PCSL_NET_IOERROR;
}