Example #1
0
result_t Socket::create(int32_t family, int32_t type)
{
    if (m_sock != INVALID_SOCKET)
    {
        if (exlib::Service::hasService())
            ac_close();
        else
        {
            asyncEvent ac;
            close(&ac);
        }
    }

    m_family = family;
    m_type = type;

    if (family == net_base::_AF_INET)
        family = AF_INET;
    else if (family == net_base::_AF_INET6)
        family = AF_INET6;
    else
        return CHECK_ERROR(CALL_E_INVALIDARG);

    if (type == net_base::_SOCK_STREAM)
        type = SOCK_STREAM;
    else if (type == net_base::_SOCK_DGRAM)
        type = SOCK_DGRAM;
    else
        return CHECK_ERROR(CALL_E_INVALIDARG);

#ifdef _WIN32

    m_sock = WSASocket(family, type, IPPROTO_IP, NULL, 0, WSA_FLAG_OVERLAPPED);
    if (m_sock == INVALID_SOCKET)
        return CHECK_ERROR(SocketError());

    CreateIoCompletionPort((HANDLE) m_sock, s_hIocp, 0, 0);

#else

    m_sock = socket(family, type, 0);
    if (m_sock == INVALID_SOCKET)
        return CHECK_ERROR(SocketError());

    fcntl(m_sock, F_SETFL, fcntl(m_sock, F_GETFL, 0) | O_NONBLOCK);
    fcntl(m_sock, F_SETFD, FD_CLOEXEC);

#endif

#ifdef MacOS

    int set_option = 1;
    setsockopt(m_sock, SOL_SOCKET, SO_NOSIGPIPE, &set_option,
               sizeof(set_option));

#endif

    return 0;
}
Example #2
0
void CALL_CONVT ac_free(lp_ac_instance pacInstance) {
  //Close the decoder. If it is already closed, this won't be a problem as ac_close checks the streams state
  ac_close(pacInstance);
  
  if (pacInstance != NULL) {
    av_free((lp_ac_data)pacInstance);
  }
}
Example #3
0
Socket::~Socket()
{
    if (m_sock != INVALID_SOCKET)
    {
        if (exlib::Service::hasService())
            ac_close();
        else
        {
            asyncEvent ac;
            close(&ac);
        }
    }
}