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