Esempio n. 1
0
/** ========================================================================
 * =========================================================================
 */
PslError
psl_inet_make_fd_non_blocking(int const fd, const char* const userLabel,
                              const void* const cookie)
{
    /// Make it non-blocking
    int const flags = fcntl(fd, F_GETFL, 0);
    if (-1 == flags) {
        int const savederrno = errno;
        PSL_LOG_ERROR("%s (%s=%p): ERROR: fcntl(%d, F_GETFL, 0) failed; " \
                      "errno=%d (%s)", __func__, userLabel, cookie, fd,
                      savederrno, strerror(savederrno));
        return psl_err_pslerror_from_errno(savederrno, PSL_ERR_SOCKET_CONFIG);
    }

    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
        int const savederrno = errno;
        PSL_LOG_ERROR("%s (%s=%p): ERROR: fcntl(%d, F_SETFL, " \
                      "flags | O_NONBLOCK) failed; errno=%d (%s)",
                      __func__, userLabel, cookie, fd, savederrno,
                      strerror(savederrno));
        return psl_err_pslerror_from_errno(savederrno, PSL_ERR_SOCKET_CONFIG);
    }

    return 0;
}//psl_inet_make_fd_non_blocking
/** ========================================================================
 * =========================================================================
 */
void
psl_chan_fsm_set_last_error(PslChanFsm*             const fsm,
                            PslChanFsmErrorSource   const errSrc,
                            int                           code)
{
    PSL_ASSERT(fsm);
    PSL_ASSERT(kPslChanFsmErrorSource_errno == errSrc ||
               kPslChanFsmErrorSource_psl == errSrc);
    PSL_ASSERT(code);

    if (kPslChanFsmErrorSource_errno == errSrc) {
        code = psl_err_pslerror_from_errno(code, PSL_ERR_FAILED);
    }

    fsm->lastError = code;
}