91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-07
  • 語言: C/C++
  • 標簽: vc??tcp/ip??網絡??

資源簡介

C++ 多線程TELNET服務程序

資源截圖

代碼片段和文件信息

//Download?by?http://www.NewXing.com
//?Copyright?(c)?1999?Lee?Patterson
//?leepatterson@home.com

//?blocksock.cpp?(CBlockingSocketException?CBlockingSocket?CHttpBlockingSocket)
#include?
#include?
#include?
#include?“blockingsocket.h“

#define?ASSERT?assert
#define?VERIFY?ASSERT


//?Class?CBlockingSocket

void?CBlockingSocket::Cleanup()
{
//?doesn‘t?throw?an?exception?because?it‘s?called?in?a?catch?block
if(m_hSocket?==?NULL)?return;
closesocket(m_hSocket);
m_hSocket?=?NULL;
}

void?CBlockingSocket::Create(int?nType?/*?=?SOCK_STREAM?*/)
{
ASSERT(m_hSocket?==?NULL);
if((m_hSocket?=?socket(AF_INET?nType?0))?==?INVALID_SOCKET)?{
throw?“Create“;
}
}

void?CBlockingSocket::Bind(LPCSOCKADDR?psa)
{
ASSERT(m_hSocket?!=?NULL);
if(bind(m_hSocket?psa?sizeof(SOCKADDR))?==?SOCKET_ERROR)?{
throw?“Bind“;
}
}

void?CBlockingSocket::Listen()
{
ASSERT(m_hSocket?!=?NULL);
if(listen(m_hSocket?5)?==?SOCKET_ERROR)?{
//throw?“Listen“;
throw?“Listen“;
}
}

bool?CBlockingSocket::Accept(CBlockingSocket&?sConnect?LPSOCKADDR?psa)
{
ASSERT(m_hSocket?!=?NULL);
ASSERT(sConnect.m_hSocket?==?NULL);
int?nLengthAddr?=?sizeof(SOCKADDR);
sConnect.m_hSocket?=?accept(m_hSocket?psa?&nLengthAddr);
if(sConnect?==?INVALID_SOCKET)?{
//?no?exception?if?the?listen?was?canceled
if(WSAGetLastError()?!=?WSAEINTR)?{
throw?“Accept“;
}
return?FALSE;
}
return?TRUE;
}

void?CBlockingSocket::Close()
{
ASSERT(m_hSocket?!=?NULL);
if(closesocket(m_hSocket)?==?SOCKET_ERROR)?{
//?should?be?OK?to?close?if?closed?already
throw?“Close“;
}
m_hSocket?=?NULL;
}

void?CBlockingSocket::Connect(LPCSOCKADDR?psa)
{
ASSERT(m_hSocket?!=?NULL);
//?should?timeout?by?itself
if(connect(m_hSocket?psa?sizeof(SOCKADDR))?==?SOCKET_ERROR)?{
throw?“Connect“;
}
}

int?CBlockingSocket::Write(const?char*?pch?const?int?nSize?const?int?nSecs)
{
int?nBytesSent?=?0;
int?nBytesThisTime;
const?char*?pch1?=?pch;
do?{
nBytesThisTime?=?Send(pch1?nSize?-?nBytesSent?nSecs);
nBytesSent?+=?nBytesThisTime;
pch1?+=?nBytesThisTime;
}?while(nBytesSent? return?nBytesSent;
}

int?CBlockingSocket::Send(const?char*?pch?const?int?nSize?const?int?nSecs)
{
ASSERT(m_hSocket?!=?NULL);
//?returned?value?will?be?less?than?nSize?if?client?cancels?the?reading
FD_SET?fd?=?{1?m_hSocket};
TIMEVAL?tv?=?{nSecs?0};
if(select(0?NULL?&fd?NULL?&tv)?==?0)?{
throw?“Send?timeout“;
}
int?nBytesSent;
if((nBytesSent?=?send(m_hSocket?pch?nSize?0))?==?SOCKET_ERROR)?{
throw?“Send“;
}
return?nBytesSent;
}

int?CBlockingSocket::Receive(char*?pch?const?int?nSize?const?int?nSecs)
{
ASSERT(m_hSocket?!=?NULL);
FD_SET?fd?=?{1?m_hSocket};
TIMEVAL?tv?=?{nSecs?0};
if(select(0?&fd?NULL?NULL?&tv)?==?0)?{
throw?“Receive?timeout“;
}

int?nBytesReceived;
if((nBytesReceived?=?recv(m_hSocket?pch?nSize?0))?==?

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????8155??2011-05-16?16:32??www.NewXing.com\blockingsocket.cpp

?????文件???????8598??2011-05-16?16:32??www.NewXing.com\gameob.cpp

?????文件???????5141??2011-05-16?16:32??www.NewXing.com\llist.cpp

?????文件??????12946??2011-05-16?16:32??www.NewXing.com\server.cpp

????.......??????3943??1999-07-02?19:30??www.NewXing.com\server.dsp

????.......???????535??1998-10-19?21:13??www.NewXing.com\server.dsw

?????文件???????3471??2011-05-16?16:32??www.NewXing.com\blockingsocket.h

?????文件???????3188??2011-05-16?16:32??www.NewXing.com\gameob.h

?????文件???????1496??2011-05-16?16:32??www.NewXing.com\llist.h

-----------?---------??----------?-----??----

????????????????47473????????????????????9


評論

共有 條評論