Exemplo n.º 1
0
bool TCPSocket::SendPacket( const Message& packet )
{
	bool result = false;
	unsigned int dataSize = sizeof( unsigned int ) + packet.GetSerializationSize();
	Byte* serializedPacket = static_cast<Byte*>( tMalloc( dataSize ) );
	Byte* walker = serializedPacket;
	SerializationUtility::CopyAndIncrementDestination( walker, &dataSize, sizeof( unsigned int ) );
	packet.Serialize( walker );

#if NETWORK_DEBUG
	if ( walker != serializedPacket + dataSize )
	{
		int differentiatingSize = static_cast<int>(walker - serializedPacket - dataSize);
		assert(false);
	}
	MemoryAllocator::VerifyPointer( serializedPacket );
#endif

	if ( serializedPacket != nullptr )
	{
		result = SendRawData( serializedPacket, dataSize );
		tFree( serializedPacket );
	}

	return result;
}
Exemplo n.º 2
0
int CCommandSocket::SendCommandData(char* pszCommand)
{
	//strlne은 null종료문자를 뺀 길이를 Return한다.
	//따라서, 내용길이+종료문자(2바이트)+종료문자(1바이트)
	char* pszLine = new char[strlen(pszCommand)+sizeof(LINE_END_CHAR)+1];
	memset(pszLine, 0x00, strlen(pszCommand)+sizeof(LINE_END_CHAR)+1);

	sprintf(pszLine, "%s%s", pszCommand, LINE_END_CHAR);

	//SendRawData는 종료문자를 빼고, 데이터를 보낸다.
	//LINE_END_CHAR의 사이즈에도 종료문자가 포함되어 있어서 빼야한다.
	//pszCommand의 사이즈느 strlen를 사용하면, 종료문자 제외한 길이가 리턴된다.
	int iResult = SendRawData(pszLine, strlen(pszCommand)+(sizeof(LINE_END_CHAR)-1));

	/*DEBUG*/
	if(iResult>0)
	{
		printf("S => %s", pszLine);
		WriteFtpCommandLog("S => %s", pszLine);
	}
	/**/

	delete [] pszLine;
	pszLine = NULL;

	return iResult;
}
Exemplo n.º 3
0
	Bool HawkSession::SendProtocol(Protocol* pProto, Bool bFlush)
	{
		if (IsValid())
		{
			//协议打包为数据流
			HawkOctetsStream xOS;
			if(!pProto->Encode(xOS))
				return false;

			return SendRawData(xOS.Begin(), xOS.Size(), bFlush);
		}
		return false;
	}
Exemplo n.º 4
0
void Server::SendBlock(CLIENT_INFO clientInfo)
{
	char buffer[BUFFER_SIZE];
	auto file = clientInfo->second;
	try {
		while (file)
		{
			file->read(buffer, BUFFER_SIZE);
			size_t read = file->gcount();
			size_t realySent = SendRawData(clientInfo->first, buffer, read);
			if (realySent != read)
			{
				fpos_t pos = file->tellg();
				file->seekg(pos - (read - realySent));
			}
		}
	} catch(std::runtime_error e) {
		
	}
	FD_CLR(clientInfo->first, &clientsSet);
	file->close();
	shutdown(clientInfo->first, SD_BOTH);
	closesocket(clientInfo->first);
}
Exemplo n.º 5
0
void ProxySession::UpdateRemote() 
{
	int ret ;
	char buf[1024*16] ;
	if(!nd_connector_valid((nd_netui_handle)m_remote_handle)) {
		return ;
	}


	ret = nd_connector_raw_waitdata(m_remote_handle, buf, sizeof(buf), 0) ;

	//ret = m_remote_connector.RecvRawData(buf, sizeof(buf),0) ;
	if(0==ret || (ret == -1 && NDERR_WUOLD_BLOCK !=nd_object_lasterror(m_remote_handle))  ) {
		Shutdown();
	}
	if(ret <= 0) {
		return ;
	}
	if (!m_is_udp) {
		SendRawData(buf, ret) ;
		return ;

	}

	//读取地址
	struct sockaddr_in* read_addr = nd_udp_read_addr(m_remote_handle) ;
	if (read_addr->sin_addr.s_addr==m_client_addr.sin_addr.s_addr && read_addr->sin_port==m_client_addr.sin_port ) {
		//来自client
		int sock_len;
		struct sockaddr_in aim_addr ;
		if(buf[0]!=0 || buf[1]!=0 || buf[2]!=0) {
			return ;
		}
		if (buf[3]==1)	{
			if(ret <= 10) {
				return ;
			}
			aim_addr.sin_addr.s_addr =*(int*) &buf[4] ;
			aim_addr.sin_port = *(short*) &buf[8] ;
			sock_len = 10;
			ret -= 10 ;
		}
		else if(buf[3]==3){
			int sock_len = buf[4] + 5;
			if ( sock_len >= ret) {
				return ;
			}

			aim_addr.sin_port = *(short *) &buf[sock_len] ;
			sock_len += 2 ;

			if ( sock_len >= ret) {
				return ;
			}
			ret -= sock_len ;

		}

		aim_addr.sin_family = AF_INET ;
		memcpy(buf, buf+sock_len, ret) ;
		nd_udp_sendto(m_remote_handle,buf,ret, &aim_addr) ; 
	}
	else {
		//来自远程
		nd_proxy_sendto(nd_connector_fd(m_remote_handle),buf,ret, read_addr, &m_client_addr) ;
	}

}
Exemplo n.º 6
0
	Bool HawkGateProxy::SendRawData(SID iSid, const OctetsStream* pData)
	{
		SvrMsgHeader sHeader;
		sHeader.Sid = iSid;
		return SendRawData(sHeader, pData);
	}