当前位置: 首页>>代码示例>>C++>>正文


C++ SetCloseAndDelete函数代码示例

本文整理汇总了C++中SetCloseAndDelete函数的典型用法代码示例。如果您正苦于以下问题:C++ SetCloseAndDelete函数的具体用法?C++ SetCloseAndDelete怎么用?C++ SetCloseAndDelete使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetCloseAndDelete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ad

int UdpSocket::Bind(const std::string& intf, port_t &port, int range)
{
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
    if (IsIpv6())
    {
        Ipv6Address ad(intf, port);
        if (ad.IsValid())
        {
            int n = Bind(ad, range);
            if (m_bind_ok)
                port = m_port;
            return n;
        }
        SetCloseAndDelete();
        return -1;
    }
#endif
#endif
    Ipv4Address ad(intf, port);
    if (ad.IsValid())
    {
        int n = Bind(ad, range);
        if (m_bind_ok)
            port = m_port;
        return n;
    }
    SetCloseAndDelete();
    return -1;
}
开发者ID:Omniasoft,项目名称:BellPi,代码行数:30,代码来源:UdpSocket.cpp

示例2: OnSocks4ConnectFailed

void SctpSocket::OnException()
{
    if (Connecting())
    {
#ifdef ENABLE_SOCKS4
        if (Socks4())
            OnSocks4ConnectFailed();
        else
#endif
        if (GetConnectionRetry() == -1 ||
            (GetConnectionRetry() &&
             GetConnectionRetries() < GetConnectionRetry() ))
        {
            // even though the connection failed at once, only retry after
            // the connection timeout
            // should we even try to connect again, when CheckConnect returns
            // false it's because of a connection error - not a timeout...
        }
        else
        {
            SetConnecting(false); // tnx snibbe
            SetCloseAndDelete();
            OnConnectFailed();
        }
        return;
    }
    // %! exception doesn't always mean something bad happened, this code should be reworked
    // errno valid here?
    int err = SoError();
    Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL);
    SetCloseAndDelete();
}
开发者ID:BornHunter,项目名称:CGSF,代码行数:32,代码来源:SctpSocket.cpp

示例3: sctp_recvmsg

void SctpSocket::OnRead()
{
/*
    int sctp_recvmsg(int sd, void * msg, size_t * len,
        struct sockaddr * from, socklen_t * fromlen,
        struct sctp_sndrcvinfo * sinfo, int * msg_flags);

    DESCRIPTION
    sctp_recvmsg  is  a  wrapper library function that can be used to receive a message from a socket while using the advanced
    features of SCTP.  sd is the socket descriptor on which the message pointed to by msg of length len is received.

    If from is not NULL, the source address of the message is filled in. The argument fromlen  is  a  value-result  parameter.
    initialized  to  the  size  of the buffer associated with from , and modified on return to indicate the actual size of the
    address stored.

    sinfo is a pointer to a sctp_sndrcvinfo structure to be filled upon receipt of the message.  msg_flags is a pointer  to  a
    integer that is filled with any message flags like MSG_NOTIFICATION or MSG_EOR.

*/
    struct sockaddr sa;
    socklen_t sa_len = 0;
    struct sctp_sndrcvinfo sinfo;
    int flags = 0;
    int n = sctp_recvmsg(GetSocket(), m_buf, SCTP_BUFSIZE_READ, &sa, &sa_len, &sinfo, &flags);
    if (n == -1)
    {
        Handler().LogError(this, "SctpSocket", Errno, StrError(Errno), LOG_LEVEL_FATAL);
        SetCloseAndDelete();
    }
    else
    {
        OnReceiveMessage(m_buf, n, &sa, sa_len, &sinfo, flags);
    }
}
开发者ID:BornHunter,项目名称:CGSF,代码行数:34,代码来源:SctpSocket.cpp

示例4: _Execute

void ControlSocket::HandleString(std::string s)
{
    if(_instance->GetConf()->rmcontrolpass.size())
    {
        if(_authed)
        {
            _Execute(s);
        }
        else
        {
            if(s.size() > 3 && !memicmp(s.c_str(),"pw ",3)) // string format: "pw secret12345"
            {
                if(_instance->GetConf()->rmcontrolpass == s.c_str() + 3)
                {
                    logdetail("ControlSocket: Authenticated successfully with: \"%s\"",s.c_str());
                    SendTelnetText("+accepted");
                    _authed = true;
                }
                else
                {
                    SendTelnetText("+wrong password");
                    SetCloseAndDelete(true);
                }
            }
        }
    }
    else
    {
        _Execute(s);
    }
}
开发者ID:Cyph3r,项目名称:pseuwow,代码行数:31,代码来源:ControlSocket.cpp

示例5: logdetail

void ControlSocket::OnAccept(void)
{
    logdetail("ControlSocket: Incoming connection from %s:%u [host:%s]",GetRemoteAddress().c_str(),GetRemotePort(),GetRemoteHostname().c_str());

    // must perform some crappy ptr conversion here, doesnt want to typecast SocketHandler -> ControlSocketHandler directly
    SocketHandler& hnd = Handler();
    ControlSocketHandler *chnd = static_cast<ControlSocketHandler*>(&hnd);
    _instance = chnd->GetInstance();
    DEBUG(logdebug("ControlSocket: setting instance = %X",_instance));

    // accept only connections from one host for now, if set
    if(_instance->GetConf()->rmcontrolhost.length()
        && !(GetRemoteAddress() == _instance->GetConf()->rmcontrolhost || GetRemoteHostname() == _instance->GetConf()->rmcontrolhost))
    {
        logdetail("ControlSocket: connection rejected. closing.");
        SetCloseAndDelete(true);
        return;
    }

    SendTelnetText(_instance->GetScripts()->variables.Get("@version"));
    if(_instance->GetConf()->rmcontrolpass.size())
    {
        SendTelnetText("Authentication?");
    }

    _ok = true;
}
开发者ID:Cyph3r,项目名称:pseuwow,代码行数:27,代码来源:ControlSocket.cpp

示例6: SetCloseAndDelete

void pSocket::SendBitmap()
{
    Session *sess = m_sess; //ref.GetSession(m_hash);
    if (!sess)
    {
        SetCloseAndDelete();
        return;
    }
    piece_v& pcs = sess -> Complete();
    // TODO: uncomment..
//	if (pcs.size())
    {
        bitmap_t bitmap(sess -> GetNumberOfPieces());
        for (piece_v::iterator it = pcs.begin(); it != pcs.end(); it++)
        {
            Piece *p = *it;
            bitmap.set(p -> GetNumber());
        }
        uint32_t l = htonl(bitmap.GetBitmapSize() + 1);
        
        SendBuf( (char *)&l, 4);
        
        Send("\05");
        SendBuf( (char *)bitmap.GetBitmap(),bitmap.GetBitmapSize());
    }
}
开发者ID:amirkrifa,项目名称:BitHoc,代码行数:26,代码来源:pSocket.cpp

示例7: Handler

void HttpPutSocket::SetFile(const std::string& file)
{
    //struct stat st;
    
    // Added by Amir Krifa
    std::ifstream f;
    f.open(file.c_str(), std::ios_base::binary | std::ios_base::in);
    //if (!f.good() || f.eof() || !f.is_open()) { return 0; }
    
    if (!f.good() || f.eof() || !f.is_open()) 
    { 
        Handler().LogError(this, "SetFile", Errno, StrError(Errno), LOG_LEVEL_FATAL);
        SetCloseAndDelete();
    }else
    {
        f.seekg(0, std::ios_base::beg);
        std::ifstream::pos_type begin_pos = f.tellg();
        f.seekg(0, std::ios_base::end);
        m_filename = file;
        m_content_length = static_cast<off_t>(f.tellg() - begin_pos);
    }
    
    //if (!stat(file.c_str(), &st))
    //{
    //	m_filename = file;
    //	m_content_length = st.st_size;
    //}
    //else
    //{
    //	Handler().LogError(this, "SetFile", Errno, StrError(Errno), LOG_LEVEL_FATAL);
    //	SetCloseAndDelete();
    //}
}
开发者ID:amirkrifa,项目名称:BitHoc,代码行数:33,代码来源:HttpPutSocket.cpp

示例8: read

void StdinLine::OnRead()
{
    char buf[m_bufsize];
    int n = read(GetSocket(), buf, m_bufsize - 1); //recv(0, buf, 1000, 0);
    if (n == -1)
    {
        Handler().LogError(this, "OnRead", errno, strerror(errno), LOG_LEVEL_FATAL);
        SetCloseAndDelete();
        return;
    }
    for (size_t i = 0; i < (size_t)n; i++)
    {
        switch (buf[i])
        {
        case 13: // ignore
            break;
        case 10:
            OnLine(m_line);
            m_line = "";
            break;
        default:
            m_line += buf[i];
        }
    }
}
开发者ID:andhikanugraha,项目名称:tetembakan,代码行数:25,代码来源:StdinLine.cpp

示例9: fwrite

void HttpClientSocket::OnData(const char *buf,size_t len)
{
    if (m_fil)
    {
        m_fil -> fwrite(buf, 1, len);
    }
    else
    if (m_data_ptr)
    {
        if (m_content_ptr + len > m_data_size)
        {
            Handler().LogError(this, "OnData", -1, "content buffer overflow", LOG_LEVEL_ERROR);
        }
        else
        {
            memcpy(m_data_ptr + m_content_ptr, buf, len);
        }
    }
    m_content_ptr += len;
    if (m_content_ptr == m_content_length && m_content_length)
    {
        if (m_fil)
        {
            m_fil -> fclose();
            delete m_fil;
            m_fil = NULL;
        }
        m_b_complete = true;
        OnContent();
        if (m_b_close_when_complete)
        {
            SetCloseAndDelete();
        }
    }
}
开发者ID:SnowfallIndustries,项目名称:Reality,代码行数:35,代码来源:HttpClientSocket.cpp

示例10: Attach

int UdpSocket::Bind(SocketAddress& ad, int range)
{
    if (GetSocket() == INVALID_SOCKET)
    {
        Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
    }
    if (GetSocket() != INVALID_SOCKET)
    {
        SetNonblocking(true);
        int n = bind(GetSocket(), ad, ad);
        int tries = range;
        while (n == -1 && tries--)
        {
            ad.SetPort(ad.GetPort() + 1);
            n = bind(GetSocket(), ad, ad);
        }
        if (n == -1)
        {
            Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL);
            SetCloseAndDelete();
#ifdef ENABLE_EXCEPTIONS
            throw Exception("bind() failed for UdpSocket, port:range: " + Utility::l2string(ad.GetPort()) + ":" + Utility::l2string(range));
#endif
            return -1;
        }
        m_bind_ok = true;
        m_port = ad.GetPort();
        return 0;
    }
    return -1;
}
开发者ID:f059074251,项目名称:interested,代码行数:31,代码来源:UdpSocket.cpp

示例11: SwitchEditors

void UBSocket::OnLine(const std::string &line)
{
    bool popLast = false;

    SwitchEditors();

    if(m_editors.empty())
    {
        Global::Get()->bugf("UBSocket::OnLine(), m_editor == NULL!");
        Send("You don't have an editor mode set?\n");
        Send("Closing your connection now.\n");
        SetCloseAndDelete();
        return;
    }

    if(line.size() && line[0] == Global::Get()->OOCIdentifier)
    {
        m_editors.push(new EditorOOC(this));
        popLast = true;
    }

    m_editors.top()->OnLine(line);

    if(popLast)
        PopEditor();

    return;
}
开发者ID:SRabbelier,项目名称:unsignedbyte,代码行数:28,代码来源:UBSocket.cpp

示例12: SetCloseAndDelete

bool TcpSocket::Open(const std::string &host,port_t port)
{
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
    if (IsIpv6())
    {
#ifdef ENABLE_RESOLVER
        if (!Handler().ResolverEnabled() || Utility::isipv6(host) )
        {
#endif
            in6_addr a;
            if (!Utility::u2ip(host, a))
            {
                SetCloseAndDelete();
                return false;
            }
            Ipv6Address ad(a, port);
            Ipv6Address local;
            return Open(ad, local);
#ifdef ENABLE_RESOLVER
        }
        m_resolver_id = Resolve6(host, port);
        return true;
#endif
    }
#endif
#endif
#ifdef ENABLE_RESOLVER
    if (!Handler().ResolverEnabled() || Utility::isipv4(host) )
    {
#endif
        ipaddr_t l;
        if (!Utility::u2ip(host,l))
        {
            SetCloseAndDelete();
            return false;
        }
        Ipv4Address ad(l, port);
        Ipv4Address local;
        return Open(ad, local);
#ifdef ENABLE_RESOLVER
    }
    // resolve using async resolver thread
    m_resolver_id = Resolve(host, port);
    return true;
#endif
}
开发者ID:peteo,项目名称:BSDSocketTest,代码行数:47,代码来源:TcpSocket.cpp

示例13: DEBUG_LOG

/// Reconnect Challenge command handler
bool AuthSocket::_HandleReconnectChallenge()
{
    DEBUG_LOG("Entering _HandleReconnectChallenge");
    if (ibuf.GetLength() < sizeof(sAuthLogonChallenge_C))
        return false;

    ///- Read the first 4 bytes (header) to get the length of the remaining of the packet
    std::vector<uint8> buf;
    buf.resize(4);

    ibuf.Read((char *)&buf[0], 4);

    EndianConvert(*((uint16*)(buf[0])));
    uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
    DEBUG_LOG("[ReconnectChallenge] got header, body is %#04x bytes", remaining);

    if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (ibuf.GetLength() < remaining))
        return false;

    //No big fear of memory outage (size is int16, i.e. < 65536)
    buf.resize(remaining + buf.size() + 1);
    buf[buf.size() - 1] = 0;
    sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];

    ///- Read the remaining of the packet
    ibuf.Read((char *)&buf[4], remaining);
    DEBUG_LOG("[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
    DEBUG_LOG("[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);

    _login = (const char*)ch->I;
    _build = ch->build;

    _safelogin = _login;
    loginDatabase.escape_string(_safelogin);

    QueryResult *result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ());

    // Stop if the account is not found
    if (!result)
    {
        sLog.outError("[ERROR] user %s tried to login and we cannot find his session key in the database.", _login.c_str());
        SetCloseAndDelete();
        return false;
    }

    Field* fields = result->Fetch ();
    K.SetHexStr (fields[0].GetString ());
    delete result;

    ///- Sending response
    ByteBuffer pkt;
    pkt << (uint8)  AUTH_RECONNECT_CHALLENGE;
    pkt << (uint8)  0x00;
    _reconnectProof.SetRand(16 * 8);
    pkt.append(_reconnectProof.AsByteArray(16),16);         // 16 bytes random
    pkt << (uint64) 0x00 << (uint64) 0x00;                  // 16 bytes zeros
    SendBuf((char const*)pkt.contents(), pkt.size());
    return true;
}
开发者ID:X-Core,项目名称:X-core-addons,代码行数:60,代码来源:AuthSocket.cpp

示例14: Send

void HttpDebugSocket::OnDataComplete()
{
    if (!CloseAndDelete())
    {
        Send("</pre><hr></body></html>");
        SetCloseAndDelete();
    }
}
开发者ID:BackupTheBerlios,项目名称:openslx-svn,代码行数:8,代码来源:HttpDebugSocket.cpp

示例15: SoError

void Socket::OnException()
{
    // %! exception doesn't always mean something bad happened, this code should be reworked
    // errno valid here?
    int err = SoError();
    Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL);
    SetCloseAndDelete();
}
开发者ID:amirkrifa,项目名称:BitHoc,代码行数:8,代码来源:socket.cpp


注:本文中的SetCloseAndDelete函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。