updated codes, and compiled ok!
This commit is contained in:
parent
228173af08
commit
e79c592464
@ -2,7 +2,7 @@
|
||||
#define HGL_NETWORK_HTTP_INPUT_STREAM_INCLUDE
|
||||
|
||||
#include<hgl/io/InputStream.h>
|
||||
#include<hgl/ut/PList.h>
|
||||
#include<hgl/util/plist/PList.h>
|
||||
#include<hgl/network/IP.h>
|
||||
namespace hgl
|
||||
{
|
||||
@ -64,7 +64,7 @@ namespace hgl
|
||||
|
||||
bool Restart() override{return false;} ///<复位访问指针
|
||||
int64 Skip(int64) override{return 0;} ///<跳过指定字节不访问
|
||||
int64 Seek(int64,SeekOrigin=soBegin) override {return false;} ///<移动访问指针
|
||||
int64 Seek(int64,SeekOrigin so=SeekOrigin::Begin) override {return false;} ///<移动访问指针
|
||||
int64 Tell()const override{return pos;} ///<返回当前访问位置
|
||||
int64 GetSize()const override{return filelength;} ///<取得流长度
|
||||
int64 Available()const override{return filelength-pos;} ///<剩下的可以不受阻塞访问的字节数
|
||||
|
@ -69,8 +69,8 @@
|
||||
|
||||
#include<hgl/type/DataType.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/Str.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/StrChar.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include<hgl/io/InputStream.h>
|
||||
namespace hgl
|
||||
{
|
||||
template<typename T> class MemBlock;
|
||||
template<typename T> class DataArray;
|
||||
|
||||
namespace network
|
||||
{
|
||||
@ -16,7 +16,7 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
int sock;
|
||||
MemBlock<char> *mb;
|
||||
DataArray<char> *mb;
|
||||
|
||||
int64 total; //累计字节数
|
||||
|
||||
@ -46,7 +46,7 @@ namespace hgl
|
||||
|
||||
bool Restart(){return false;} ///<复位访问指针
|
||||
int64 Skip(int64); ///<跳过指定字节不访问
|
||||
int64 Seek(int64,io::SeekOrigin=io::soBegin){return -1;} ///<移动访问指针
|
||||
int64 Seek(int64,io::SeekOrigin=io::SeekOrigin::Begin){return -1;} ///<移动访问指针
|
||||
int64 Tell()const{return -1;} ///<返回当前访问位置
|
||||
int64 GetSize()const{return -1;} ///<取得流长度
|
||||
int64 Available()const; ///<剩下的可以不受阻塞访问的字节数
|
||||
|
@ -30,7 +30,7 @@ namespace hgl
|
||||
sock_send_list,
|
||||
sock_error_list;
|
||||
|
||||
Set<TCPAccept *> error_set;
|
||||
SortedSets<TCPAccept *> error_sets;
|
||||
|
||||
protected:
|
||||
|
||||
@ -42,7 +42,7 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
const Set<TCPAccept *> &GetErrorSocketSet(){return error_set;} ///<获取错误SOCKET合集
|
||||
const SortedSets<TCPAccept *> &GetErrorSocketSet(){return error_sets;} ///<获取错误SOCKET合集
|
||||
|
||||
public:
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace hgl
|
||||
bool CanSize()const{return false;} ///<是否可以取得尺寸
|
||||
|
||||
bool Restart(){return false;} ///<复位访问指针
|
||||
int64 Seek(int64,io::SeekOrigin=io::soBegin){return -1;} ///<移动访问指针
|
||||
int64 Seek(int64,io::SeekOrigin=io::SeekOrigin::Begin){return -1;} ///<移动访问指针
|
||||
int64 Tell()const{return -1;} ///<返回当前访问位置
|
||||
int64 GetSize()const{return -1;} ///<取得流长度
|
||||
int64 Available()const; ///<剩下的可以不受阻塞写入的字节数
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define HGL_NETWORK_TCP_ACCEPT_INCLUDE
|
||||
|
||||
#include<hgl/network/TCPSocket.h>
|
||||
#include<hgl/type/MemBlock.h>
|
||||
#include<hgl/type/DataArray.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace network
|
||||
@ -60,7 +60,7 @@ namespace hgl
|
||||
{
|
||||
protected:
|
||||
|
||||
MemBlock<uchar> recv_buffer;
|
||||
DataArray<uchar> recv_buffer;
|
||||
uint recv_length=0;
|
||||
|
||||
uint64 recv_total=0;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_NETWORK_WEBSOCKET_INCLUDE
|
||||
#define HGL_NETWORK_WEBSOCKET_INCLUDE
|
||||
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/type/String.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace network
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define HGL_NETWORK_WEBSOCKET_ACCEPT_INCLUDE
|
||||
|
||||
#include<hgl/network/TCPAccept.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/type/String.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace network
|
||||
@ -13,11 +13,11 @@ namespace hgl
|
||||
class WebSocketAccept:public TCPAccept
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
MemBlock<char> data_out_str;
|
||||
DataArray<char> data_out_str;
|
||||
#endif//_DEBUG
|
||||
protected:
|
||||
|
||||
MemBlock<uchar> recv_buffer;
|
||||
DataArray<uchar> recv_buffer;
|
||||
uint recv_length=0;
|
||||
|
||||
uint64 recv_total=0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/AcceptServer.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/Time.h>
|
||||
|
||||
namespace hgl
|
||||
@ -49,7 +49,7 @@ namespace hgl
|
||||
)
|
||||
return(0);
|
||||
|
||||
LOG_HINT(OS_TEXT("AcceptServer Accept error,errno=")+OSString(err));
|
||||
LOG_HINT(OS_TEXT("AcceptServer Accept error,errno=")+OSString::numberOf(err));
|
||||
|
||||
if(err==nseTooManyLink) //太多的人accept
|
||||
{
|
||||
@ -67,7 +67,7 @@ namespace hgl
|
||||
|
||||
addr->ToString(ipstr,IP_STR_MAX_SIZE);
|
||||
|
||||
LOG_INFO(U8_TEXT("AcceptServer Accept IP:")+UTF8String(ipstr)+U8_TEXT(" ,sock:")+UTF8String(new_sock));
|
||||
LOG_INFO(U8_TEXT("AcceptServer Accept IP:")+UTF8String(ipstr)+U8_TEXT(" ,sock:")+UTF8String::numberOf(new_sock));
|
||||
|
||||
return(new_sock);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include<hgl/network/HTTPInputStream.h>
|
||||
#include<hgl/network/TCPClient.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/type/Smart.h>
|
||||
|
||||
namespace hgl
|
||||
@ -127,7 +127,7 @@ namespace hgl
|
||||
if(!offset)
|
||||
return;
|
||||
|
||||
response_info.Set(http_header,offset-http_header);
|
||||
response_info.SetString(http_header,offset-http_header);
|
||||
|
||||
char *first=strchr(http_header,' ');
|
||||
|
||||
@ -150,14 +150,14 @@ namespace hgl
|
||||
UTF8String key;
|
||||
UTF8String value;
|
||||
|
||||
key.Set(first,second-first);
|
||||
key.SetString(first,second-first);
|
||||
|
||||
first=second+2;
|
||||
second=strstr(first,http_header_size-(first-http_header),HTTP_HEADER_SPLITE,HTTP_HEADER_SPLITE_SIZE);
|
||||
|
||||
if(!second)break;
|
||||
|
||||
value.Set(first,second-first);
|
||||
value.SetString(first,second-first);
|
||||
offset=second;
|
||||
|
||||
response_list.Add(key,value);
|
||||
@ -215,7 +215,7 @@ namespace hgl
|
||||
if(err==nseWouldBlock)return(0); //不能立即完成
|
||||
if(err==0)return(0);
|
||||
|
||||
LOG_ERROR(OSString("Socket Error: ")+GetSocketString(err));
|
||||
LOG_ERROR(OSString(OS_TEXT("Socket Error: "))+GetSocketString(err));
|
||||
|
||||
Close();
|
||||
RETURN_ERROR(-2);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/IP.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@ -79,7 +79,7 @@ namespace hgl
|
||||
|
||||
if (bind(ThisSocket, (SockAddr *)&addr, sizeof(SockAddrIn)))
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Bind Socket Error! errno: ") + OSString(GetLastSocketError()));
|
||||
LOG_ERROR(OS_TEXT("Bind Socket Error! errno: ") + OSString::numberOf(GetLastSocketError()));
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace hgl
|
||||
{
|
||||
int count=ip_stack.GetCount();
|
||||
|
||||
ip_stack.SetMax(count+1024);
|
||||
ip_stack.SetMaxCount(count+1024);
|
||||
|
||||
server->CreateIPAddress(ip_stack.GetData()+count,1024);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/ServerSocket.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/Socket.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<time.h>
|
||||
#include<iostream>
|
||||
|
||||
@ -57,16 +57,16 @@ namespace hgl
|
||||
{
|
||||
const int sock_error=GetLastSocketError(); //在这里定义一个,是为了调试方便可以查看
|
||||
|
||||
LOG_ERROR(OS_TEXT("CreateSocket(domain=")+OSString(addr->GetFamily())+
|
||||
OS_TEXT(",type=")+OSString(addr->GetSocketType())+
|
||||
OS_TEXT(",protocol=")+OSString(protocol)+
|
||||
OS_TEXT(") return ")+OSString(s)+
|
||||
OS_TEXT("; errno ")+OSString(sock_error));
|
||||
LOG_ERROR( OS_TEXT("CreateSocket(domain=")+OSString::numberOf(addr->GetFamily())+
|
||||
OS_TEXT(",type=")+OSString::numberOf(addr->GetSocketType())+
|
||||
OS_TEXT(",protocol=")+OSString::numberOf(protocol)+
|
||||
OS_TEXT(") return ")+OSString::numberOf(s)+
|
||||
OS_TEXT("; errno ")+OSString::numberOf(sock_error));
|
||||
|
||||
RETURN_ERROR(-3);
|
||||
}
|
||||
|
||||
LOG_INFO(U8_TEXT("Create ")+UTF8String(addr->GetProtocolName())+U8_TEXT(" Socket OK: ")+UTF8String(s));
|
||||
LOG_INFO(U8_TEXT("Create ")+UTF8String(addr->GetProtocolName())+U8_TEXT(" Socket OK: ")+UTF8String::numberOf(s));
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -423,7 +423,7 @@ namespace hgl
|
||||
#ifdef _WIN32
|
||||
closesocket(ThisSocket);
|
||||
|
||||
LOG_INFO(OS_TEXT("CloseSocket: ") + OSString(ThisSocket));
|
||||
LOG_INFO(OS_TEXT("CloseSocket: ") + OSString::numberOf(ThisSocket));
|
||||
#else
|
||||
int result;
|
||||
|
||||
@ -433,13 +433,13 @@ namespace hgl
|
||||
|
||||
result=close(ThisSocket);
|
||||
|
||||
LOG_INFO(OS_TEXT("CloseSocket: ")+OSString(ThisSocket)+OS_TEXT(",result:")+OSString(result)+OS_TEXT(",errno: ")+OSString(errno));
|
||||
LOG_INFO(OS_TEXT("CloseSocket: ")+OSString(ThisSocket)+OS_TEXT(",result:")+OSString::numberOf(result)+OS_TEXT(",errno: ")+OSString::numberOf(errno));
|
||||
|
||||
if(errno==EBADF)break;
|
||||
if(errno==EINPROGRESS)continue;
|
||||
}while(result);
|
||||
|
||||
LOG_INFO(OS_TEXT("CloseSocket: ") + OSString(ThisSocket) + OS_TEXT(",result:") + OSString(result));
|
||||
LOG_INFO(OS_TEXT("CloseSocket: ") + OSString(ThisSocket) + OS_TEXT(",result:") + OSString::numberOf(result));
|
||||
#endif//_WIN32
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include<hgl/network/SocketInputStream.h>
|
||||
#include<hgl/io/DataInputStream.h>
|
||||
#include<hgl/network/TCPSocket.h>
|
||||
#include<hgl/type/MemBlock.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/type/DataArray.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace network
|
||||
@ -23,12 +23,12 @@ namespace hgl
|
||||
// LOG_INFO(OS_TEXT("SocketInputStream::SocketInputStream(")+OSString(s)+OS_TEXT(")"));
|
||||
|
||||
SetSocket(s);
|
||||
mb=new MemBlock<char>();
|
||||
mb=new DataArray<char>();
|
||||
}
|
||||
|
||||
SocketInputStream::~SocketInputStream()
|
||||
{
|
||||
// LOG_INFO(OS_TEXT("SocketInputStream::~SocketInputStream(")+OSString(sock)+OS_TEXT(")"));
|
||||
// LOG_INFO(OS_TEXT("SocketInputStream::~SocketInputStream(")+OSString::numberOf(sock)+OS_TEXT(")"));
|
||||
|
||||
SAFE_CLEAR(mb);
|
||||
}
|
||||
@ -51,13 +51,13 @@ namespace hgl
|
||||
if(size==0)return(0);
|
||||
if(size<0)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Read() fatal error,size<0,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Read() fatal error,size<0,sock=")+OSString::numberOf(sock));
|
||||
return(-3);
|
||||
}
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Read() fatal error,buf=nullptr,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Read() fatal error,buf=nullptr,sock=")+OSString::numberOf(sock));
|
||||
return(-2);
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ namespace hgl
|
||||
{
|
||||
total+=result;
|
||||
|
||||
// LOG_INFO(OS_TEXT("Socket ")+OSString(sock)+OS_TEXT(" recv ")+OSString(size)+OS_TEXT(" bytes ok,result ")+OSString(result)+OS_TEXT(" total recv ")+OSString(total)+OS_TEXT(" bytes."));
|
||||
// LOG_INFO(OS_TEXT("Socket ")+OSString::numberOf(sock)+OS_TEXT(" recv ")+OSString::numberOf(size)+OS_TEXT(" bytes ok,result ")+OSString(result)+OS_TEXT(" total recv ")+OSString(total)+OS_TEXT(" bytes."));
|
||||
}
|
||||
else if(result<0)
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace hgl
|
||||
if(err==nseWouldBlock)
|
||||
return 0;
|
||||
|
||||
LOG_INFO(OS_TEXT("Socket ")+OSString(sock)+OS_TEXT(" recv ")+OSString(size)+OS_TEXT(" bytes failed,error: ")+OSString(err)+OS_TEXT(",")+GetSocketString(err));
|
||||
LOG_INFO(OS_TEXT("Socket ")+OSString::numberOf(sock)+OS_TEXT(" recv ")+OSString::numberOf(size)+OS_TEXT(" bytes failed,error: ")+OSString::numberOf(err)+OS_TEXT(",")+GetSocketString(err));
|
||||
}
|
||||
|
||||
return(result);
|
||||
@ -99,13 +99,13 @@ namespace hgl
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Peek() fatal error,buf=nullptr,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Peek() fatal error,buf=nullptr,sock=")+OSString::numberOf(sock));
|
||||
return(-2);
|
||||
}
|
||||
|
||||
if(size<=0)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Peek() fatal error,size<=0,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::Peek() fatal error,size<=0,sock=")+OSString::numberOf(sock));
|
||||
return(-3);
|
||||
}
|
||||
|
||||
@ -130,13 +130,13 @@ namespace hgl
|
||||
if(size==0)return(0);
|
||||
if(size<0)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully() fatal error,size<0,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully() fatal error,size<0,sock=")+OSString::numberOf(sock));
|
||||
return(-3);
|
||||
}
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully() fatal error,buf=nullptr,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully() fatal error,buf=nullptr,sock=")+OSString::numberOf(sock));
|
||||
return(-2);
|
||||
}
|
||||
|
||||
@ -188,17 +188,17 @@ namespace hgl
|
||||
// continue;
|
||||
// }
|
||||
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully TimeOut,Socket:")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully TimeOut,Socket:")+OSString::numberOf(sock));
|
||||
}
|
||||
|
||||
err_str=GetSocketString(err);
|
||||
if(err_str)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully error,Socket:")+OSString(sock)+OS_TEXT(",error code=")+OSString(err)+OS_TEXT(":")+OSString(err_str));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully error,Socket:")+OSString::numberOf(sock)+OS_TEXT(",error code=")+OSString::numberOf(err)+OS_TEXT(":")+OSString(err_str));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully error,Socket:")+OSString(sock)+OS_TEXT(",error code=")+OSString(err));
|
||||
LOG_ERROR(OS_TEXT("SocketInputStream::ReadFully error,Socket:")+OSString::numberOf(sock)+OS_TEXT(",error code=")+OSString::numberOf(err));
|
||||
}
|
||||
|
||||
sock=-1;
|
||||
@ -219,7 +219,7 @@ namespace hgl
|
||||
// result=(p-(char *)buf);
|
||||
// total+=result;
|
||||
//
|
||||
// LOG_INFO(OS_TEXT("Socket ")+OSString(sock)+OS_TEXT(" recv ")+OSString(result)+OS_TEXT(" bytes,total recv ")+OSString(total)+OS_TEXT(" bytes."));
|
||||
// LOG_INFO(OS_TEXT("Socket ")+OSString::numberOf(sock)+OS_TEXT(" recv ")+OSString(result)+OS_TEXT(" bytes,total recv ")+OSString(total)+OS_TEXT(" bytes."));
|
||||
// #else
|
||||
total+=(p-(char *)buf);
|
||||
// #endif//_DEBUG
|
||||
@ -231,7 +231,7 @@ namespace hgl
|
||||
{
|
||||
if(n<=0)return(n);
|
||||
|
||||
mb->SetLength(n);
|
||||
mb->SetCount(n);
|
||||
|
||||
return ReadFully(mb->data(),n);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/SocketManage.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include"SocketManageBase.h"
|
||||
|
||||
namespace hgl
|
||||
@ -31,13 +31,13 @@ namespace hgl
|
||||
{
|
||||
if(sock->OnSocketRecv(se->error)<0)
|
||||
{
|
||||
LOG_INFO(OS_TEXT("OnSocketRecv return Error,sock:")+OSString(se->sock));
|
||||
error_set.Add(sock);
|
||||
LOG_INFO(OS_TEXT("OnSocketRecv return Error,sock:")+OSString::numberOf(se->sock));
|
||||
error_sets.Add(sock);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Fatal error,can't find socket in SocketList,sock is ")+OSString(se->sock));
|
||||
LOG_ERROR(OS_TEXT("Fatal error,can't find socket in SocketList,sock is ")+OSString::numberOf(se->sock));
|
||||
}
|
||||
|
||||
++se;
|
||||
@ -61,13 +61,13 @@ namespace hgl
|
||||
{
|
||||
if(sock->OnSocketSend(se->size)<0)
|
||||
{
|
||||
LOG_INFO(OS_TEXT("OnSocketSend return Error,sock:")+OSString(se->sock));
|
||||
error_set.Add(sock);
|
||||
LOG_INFO(OS_TEXT("OnSocketSend return Error,sock:")+OSString::numberOf(se->sock));
|
||||
error_sets.Add(sock);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Fatal error,can't find socket in SocketList,sock is ")+OSString(se->sock));
|
||||
LOG_ERROR(OS_TEXT("Fatal error,can't find socket in SocketList,sock is ")+OSString::numberOf(se->sock));
|
||||
}
|
||||
|
||||
++se;
|
||||
@ -89,13 +89,13 @@ namespace hgl
|
||||
{
|
||||
if(socket_list.Get(se->sock,sock))
|
||||
{
|
||||
LOG_INFO(OS_TEXT("SocketError,sock:")+OSString(se->sock)+OS_TEXT(",errno:")+OSString(se->error));
|
||||
LOG_INFO(OS_TEXT("SocketError,sock:")+OSString::numberOf(se->sock)+OS_TEXT(",errno:")+OSString::numberOf(se->error));
|
||||
sock->OnSocketError(se->error);
|
||||
error_set.Add(sock);
|
||||
error_sets.Add(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Fatal error,can't find socket in SocketList,sock is ")+OSString(se->sock));
|
||||
LOG_ERROR(OS_TEXT("Fatal error,can't find socket in SocketList,sock is ")+OSString::numberOf(se->sock));
|
||||
}
|
||||
|
||||
++se;
|
||||
@ -106,11 +106,11 @@ namespace hgl
|
||||
|
||||
void SocketManage::ProcErrorList()
|
||||
{
|
||||
const int count=error_set.GetCount();
|
||||
const int count=error_sets.GetCount();
|
||||
|
||||
if(count<=0)return;
|
||||
|
||||
TCPAccept **sp=error_set.GetData();
|
||||
TCPAccept **sp=error_sets.GetData();
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
@ -127,7 +127,7 @@ namespace hgl
|
||||
|
||||
if(!socket_list.Add(s->ThisSocket,s))
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("repeat append socket to manage,sock:")+OSString(s->ThisSocket));
|
||||
LOG_ERROR(OS_TEXT("repeat append socket to manage,sock:")+OSString::numberOf(s->ThisSocket));
|
||||
return(false);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ namespace hgl
|
||||
|
||||
if(!socket_list.DeleteByKey(s->ThisSocket))
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("socket don't in SocketManage,sock:")+OSString(s->ThisSocket));
|
||||
LOG_ERROR(OS_TEXT("socket don't in SocketManage,sock:")+OSString::numberOf(s->ThisSocket));
|
||||
return(false);
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ namespace hgl
|
||||
int SocketManage::Update(const double &time_out)
|
||||
{
|
||||
//将error_set放在这里,是为了保留它给外面的调用者使用
|
||||
error_set.ClearData();
|
||||
error_sets.ClearData();
|
||||
|
||||
const int count=manage->Update(time_out,sock_recv_list,sock_send_list,sock_error_list);
|
||||
|
||||
@ -212,7 +212,7 @@ namespace hgl
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
Unjoin((*us)->right);
|
||||
Unjoin((*us)->value);
|
||||
|
||||
++us;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include"SocketManageBase.h"
|
||||
#include<hgl/network/Socket.h>
|
||||
#include<hgl/Time.h>
|
||||
#include<hgl/type/Set.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@ -17,7 +17,7 @@ namespace hgl
|
||||
|
||||
int max_fd;
|
||||
|
||||
Set<int> sock_id_list;
|
||||
SortedSets<int> sock_id_list;
|
||||
|
||||
fd_set fd_sock_list; //完整的sock列表
|
||||
|
||||
@ -51,7 +51,7 @@ namespace hgl
|
||||
|
||||
cur_count++;
|
||||
|
||||
LOG_INFO(OS_TEXT("Join ")+OSString(sock)+OS_TEXT(" to SocketManageSelect"));
|
||||
LOG_INFO(OS_TEXT("Join ")+OSString::numberOf(sock)+OS_TEXT(" to SocketManageSelect"));
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace hgl
|
||||
|
||||
sock_id_list.Delete(sock);
|
||||
|
||||
LOG_INFO(OS_TEXT("Unjoin ")+OSString(sock)+OS_TEXT(" from SocketManageSelect"));
|
||||
LOG_INFO(OS_TEXT("Unjoin ")+OSString::numberOf(sock)+OS_TEXT(" from SocketManageSelect"));
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -122,7 +122,7 @@ namespace hgl
|
||||
|
||||
if(select(max_fd+1,&fd_recv_list,&fd_send_list,&fd_error_list,time_par)<0)
|
||||
{
|
||||
LOG_INFO(OS_TEXT("select return -1,errno: ")+OSString(errno));
|
||||
LOG_INFO(OS_TEXT("select return -1,errno: ")+OSString::numberOf(errno));
|
||||
|
||||
if(errno==EBADF
|
||||
||errno==EFAULT
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include<hgl/network/SocketOutputStream.h>
|
||||
#include<hgl/io/DataOutputStream.h>
|
||||
#include<hgl/network/TCPSocket.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace network
|
||||
@ -40,13 +40,13 @@ namespace hgl
|
||||
if(size==0)return(0);
|
||||
if(size<0)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::Write() fatal error,size<0,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::Write() fatal error,size<0,sock=")+OSString::numberOf(sock));
|
||||
return(-3);
|
||||
}
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::Write() fatal error,buf=nullptr,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::Write() fatal error,buf=nullptr,sock=")+OSString::numberOf(sock));
|
||||
return(-2);
|
||||
}
|
||||
|
||||
@ -56,13 +56,13 @@ namespace hgl
|
||||
{
|
||||
total+=result;
|
||||
|
||||
// LOG_INFO(OS_TEXT("Socket ")+OSString(sock)+OS_TEXT(" send ")+OSString(size)+OS_TEXT(" bytes ok,result ")+OSString(result)+OS_TEXT(" total send ")+OSString(total)+OS_TEXT(" bytes."));
|
||||
// LOG_INFO(OS_TEXT("Socket ")+OSString::numberOf(sock)+OS_TEXT(" send ")+OSString::numberOf(size)+OS_TEXT(" bytes ok,result ")+OSString(result)+OS_TEXT(" total send ")+OSString(total)+OS_TEXT(" bytes."));
|
||||
}
|
||||
else
|
||||
{
|
||||
int err=GetLastSocketError();
|
||||
|
||||
LOG_INFO(OS_TEXT("Socket ")+OSString(sock)+OS_TEXT(" send ")+OSString(size)+OS_TEXT(" bytes failed,,error: ")+OSString(err)+OS_TEXT(",")+GetSocketString(err));
|
||||
LOG_INFO(OS_TEXT("Socket ")+OSString::numberOf(sock)+OS_TEXT(" send ")+OSString::numberOf(size)+OS_TEXT(" bytes failed,,error: ")+OSString::numberOf(err)+OS_TEXT(",")+GetSocketString(err));
|
||||
}
|
||||
|
||||
return(result);
|
||||
@ -87,13 +87,13 @@ namespace hgl
|
||||
|
||||
if(size<0)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully() fatal error,size<0,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully() fatal error,size<0,sock=")+OSString::numberOf(sock));
|
||||
return(-3);
|
||||
}
|
||||
|
||||
if(!buf)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully() fatal error,buf=nullptr,sock=")+OSString(sock));
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully() fatal error,buf=nullptr,sock=")+OSString::numberOf(sock));
|
||||
return(-2);
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ namespace hgl
|
||||
{
|
||||
result=send(sock,p,left_bytes,0);
|
||||
|
||||
// LOG_ERROR(OS_TEXT("socket send result, left_bytes: ")+OSString(sock)+OSString(" , ")+OSString((int)result)+OSString(" , ")+OSString((int)left_bytes));
|
||||
// LOG_ERROR(OS_TEXT("socket send result, left_bytes: ")+OSString::numberOf(sock)+OSString(" , ")+OSString((int)result)+OSString(" , ")+OSString((int)left_bytes));
|
||||
if(result==0)
|
||||
{
|
||||
sock=-1;
|
||||
@ -142,11 +142,11 @@ namespace hgl
|
||||
err_str=GetSocketString(err);
|
||||
if(err_str)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully error,Socket:")+OSString(sock)+OS_TEXT(",error code=")+OSString(err)+OS_TEXT(":")+OSString(err_str));
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully error,Socket:")+OSString::numberOf(sock)+OS_TEXT(",error code=")+OSString::numberOf(err)+OS_TEXT(":")+OSString(err_str));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully error,Socket:")+OSString(sock)+OS_TEXT(",error code=")+OSString(err));
|
||||
LOG_ERROR(OS_TEXT("SocketOutputStream::WriteFully error,Socket:")+OSString::numberOf(sock)+OS_TEXT(",error code=")+OSString::numberOf(err));
|
||||
}
|
||||
sock=-1;
|
||||
break;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include<hgl/network/SocketOutputStream.h>
|
||||
#include<hgl/io/DataInputStream.h>
|
||||
#include<hgl/io/DataOutputStream.h>
|
||||
#include<hgl/Str.h>
|
||||
#include<hgl/type/StrChar.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include<hgl/network/SocketOutputStream.h>
|
||||
#include<hgl/io/DataInputStream.h>
|
||||
#include<hgl/io/DataOutputStream.h>
|
||||
#include<hgl/Str.h>
|
||||
#include<hgl/type/StrChar.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@ -53,7 +53,7 @@ namespace hgl
|
||||
|
||||
PACKET_SIZE_TYPE pack_size=*(PACKET_SIZE_TYPE *)(recv_buffer.data());
|
||||
|
||||
recv_buffer.SetLength(PACKET_SIZE_TYPE_BYTES+pack_size);
|
||||
recv_buffer.SetCount(PACKET_SIZE_TYPE_BYTES+pack_size);
|
||||
|
||||
int result=sis->Read(recv_buffer.data()+recv_length,pack_size-(recv_length-PACKET_SIZE_TYPE_BYTES));
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/TCPClient.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/network/SocketInputStream.h>
|
||||
#include<hgl/network/SocketOutputStream.h>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/TCPSocket.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
#if HGL_OS != HGL_OS_Windows
|
||||
#include<netinet/tcp.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/network/UdpSocket.h>
|
||||
#include<string.h>
|
||||
|
||||
|
@ -2,14 +2,11 @@
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/io/MemoryOutputStream.h>
|
||||
#include<hgl/util/hash/Hash.h>
|
||||
#include<hgl/algorithm/Crypt.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace network
|
||||
{
|
||||
using namespace hgl::algorithm;
|
||||
|
||||
/**
|
||||
* 获取WebSocket信息
|
||||
* @param data 输入的信息头
|
||||
@ -53,7 +50,7 @@ namespace hgl
|
||||
end=protocol;
|
||||
while(*end!='\r')++end;
|
||||
|
||||
sec_websocket_protocol.Set(protocol,end-protocol);
|
||||
sec_websocket_protocol.SetString(protocol,end-protocol);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,33 +70,34 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成WebSocket回复头
|
||||
* @param result 回复头存放字符串
|
||||
*/
|
||||
void MakeWebSocketAccept(UTF8String &result,const UTF8String &sec_websocket_key,const UTF8String &sec_websocket_protocol)
|
||||
{
|
||||
const UTF8String key_mask=sec_websocket_key+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
///**
|
||||
/// 这函数可以用,只是这版SDK没有base64_encode,所以暂时屏蔽
|
||||
// * 生成WebSocket回复头
|
||||
// * @param result 回复头存放字符串
|
||||
// */
|
||||
//void MakeWebSocketAccept(UTF8String &result,const UTF8String &sec_websocket_key,const UTF8String &sec_websocket_protocol)
|
||||
//{
|
||||
// const UTF8String key_mask=sec_websocket_key+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
HashCodeSHA1 hc;
|
||||
// util::HashCodeSHA1 hc;
|
||||
|
||||
CountSHA1(key_mask.c_str(),key_mask.Length(),hc);
|
||||
// CountSHA1(key_mask.c_str(),key_mask.Length(),hc);
|
||||
|
||||
io::MemoryOutputStream mos;
|
||||
// io::MemoryOutputStream mos;
|
||||
|
||||
base64_encode(&mos,hc.code,hc.size());
|
||||
// base64_encode(&mos,hc.code,hc.size());
|
||||
|
||||
const UTF8String sec_websocket_accept((char *)mos.GetData(),mos.GetSize());
|
||||
// const UTF8String sec_websocket_accept((char *)mos.GetData(),mos.GetSize());
|
||||
|
||||
result="HTTP/1.1 101 Switching Protocols\r\n"
|
||||
"Upgrade: websocket\r\n"
|
||||
"Connection: Upgrade\r\n"
|
||||
"Sec-WebSocket-Accept: "+sec_websocket_accept;
|
||||
// result="HTTP/1.1 101 Switching Protocols\r\n"
|
||||
// "Upgrade: websocket\r\n"
|
||||
// "Connection: Upgrade\r\n"
|
||||
// "Sec-WebSocket-Accept: "+sec_websocket_accept;
|
||||
|
||||
if(!sec_websocket_protocol.IsEmpty())
|
||||
result+="\r\nSec-WebSocket-Protocol: "+sec_websocket_protocol;
|
||||
// if(!sec_websocket_protocol.IsEmpty())
|
||||
// result+="\r\nSec-WebSocket-Protocol: "+sec_websocket_protocol;
|
||||
|
||||
result+="\r\n\r\n";
|
||||
}
|
||||
// result+="\r\n\r\n";
|
||||
//}
|
||||
}//namespace network
|
||||
}//namespace hgl
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include<hgl/network/WebSocket.h>
|
||||
#include<hgl/network/SocketInputStream.h>
|
||||
#include<hgl/network/SocketOutputStream.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@ -23,7 +23,7 @@ namespace hgl
|
||||
constexpr char HTTP_HEADER_END_STR[4]={'\r','\n','\r','\n'}; //别用"\r\n\r\n",不然sizeof会得出来5
|
||||
constexpr int HTTP_HEADER_END_SIZE=sizeof(HTTP_HEADER_END_STR);
|
||||
|
||||
MemBlock<char> ws_header(1024);
|
||||
DataArray<char> ws_header(1024);
|
||||
|
||||
int pos=0;
|
||||
int total=0;
|
||||
@ -178,7 +178,7 @@ namespace hgl
|
||||
if(msg_masked)
|
||||
msg_full_length+=4;
|
||||
|
||||
recv_buffer.SetLength(msg_full_length);
|
||||
recv_buffer.SetCount(msg_full_length);
|
||||
|
||||
int result=sis->Read(recv_buffer.data()+recv_length,msg_full_length-(recv_length-msg_header_size));
|
||||
|
||||
@ -231,11 +231,11 @@ namespace hgl
|
||||
if(msg_length>0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
data_out_str.SetLength(msg_length*3);
|
||||
data_out_str.SetCount(msg_length*3);
|
||||
|
||||
DataToLowerHexStr(data_out_str.data(),(uint8 *)pack,msg_length,',');
|
||||
|
||||
LOG_INFO(U8_TEXT("WebSocket[")+UTF8String(ThisSocket)+U8_TEXT("] Recv binary [")+UTF8String(msg_length)+U8_TEXT("]: ")+UTF8String(data_out_str.data()));
|
||||
LOG_INFO(U8_TEXT("WebSocket[")+UTF8String::numberOf(ThisSocket)+U8_TEXT("] Recv binary [")+UTF8String::numberOf(msg_length)+U8_TEXT("]: ")+UTF8String(data_out_str.data()));
|
||||
#endif//_DEBUG
|
||||
|
||||
OnBinary(pack,msg_length,msg_fin);
|
||||
@ -261,7 +261,7 @@ namespace hgl
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_PROBLEM(OS_TEXT("WebSocketAccept,opcode error,opcode:")+OSString(msg_opcode)+OS_TEXT(",length:")+OSString(msg_length));
|
||||
LOG_PROBLEM(OS_TEXT("WebSocketAccept,opcode error,opcode:")+OSString::numberOf(msg_opcode)+OS_TEXT(",length:")+OSString::numberOf(msg_length));
|
||||
OnError();
|
||||
}
|
||||
|
||||
@ -334,11 +334,11 @@ namespace hgl
|
||||
bool WebSocketAccept::SendBinary(void *data,uint32 size,bool fin)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
data_out_str.SetLength(size*3);
|
||||
data_out_str.SetCount(size*3);
|
||||
|
||||
DataToLowerHexStr(data_out_str.data(),(uint8 *)data,size,',');
|
||||
|
||||
LOG_INFO(U8_TEXT("WebSocket[")+UTF8String(ThisSocket)+U8_TEXT("] Send binary [")+UTF8String(size)+U8_TEXT("]: ")+UTF8String(data_out_str.data()));
|
||||
LOG_INFO(U8_TEXT("WebSocket[")+UTF8String::numberOf(ThisSocket)+U8_TEXT("] Send binary [")+UTF8String::numberOf(size)+U8_TEXT("]: ")+UTF8String(data_out_str.data()));
|
||||
#endif//_DEBUG
|
||||
|
||||
return SendFrame(0x2,data,size,fin)>0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/network/WinFireWall.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<netfw.h>
|
||||
|
||||
namespace hgl
|
||||
|
Loading…
x
Reference in New Issue
Block a user