mirror of
https://github.com/wolfpld/tracy
synced 2025-04-30 04:43:53 +00:00
Don't use std::function in sockets.
This commit is contained in:
parent
a2187565d1
commit
e4ec666479
@ -221,13 +221,8 @@ int Socket::Recv( void* _buf, int len, int timeout )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::Read( void* _buf, int len, int timeout, std::function<bool()> exitCb )
|
bool Socket::ReadImpl( char*& buf, int& len, int timeout )
|
||||||
{
|
{
|
||||||
auto buf = (char*)_buf;
|
|
||||||
|
|
||||||
while( len > 0 )
|
|
||||||
{
|
|
||||||
if( exitCb() ) return false;
|
|
||||||
const auto sz = RecvBuffered( buf, len, timeout );
|
const auto sz = RecvBuffered( buf, len, timeout );
|
||||||
switch( sz )
|
switch( sz )
|
||||||
{
|
{
|
||||||
@ -246,8 +241,6 @@ bool Socket::Read( void* _buf, int len, int timeout, std::function<bool()> exitC
|
|||||||
buf += sz;
|
buf += sz;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#ifndef __TRACYSOCKET_HPP__
|
#ifndef __TRACYSOCKET_HPP__
|
||||||
#define __TRACYSOCKET_HPP__
|
#define __TRACYSOCKET_HPP__
|
||||||
|
|
||||||
#include <functional>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "TracyForceInline.hpp"
|
||||||
|
|
||||||
struct sockaddr;
|
struct sockaddr;
|
||||||
|
|
||||||
@ -25,7 +27,18 @@ public:
|
|||||||
int Send( const void* buf, int len );
|
int Send( const void* buf, int len );
|
||||||
int GetSendBufSize();
|
int GetSendBufSize();
|
||||||
|
|
||||||
bool Read( void* buf, int len, int timeout, std::function<bool()> exitCb );
|
template<typename ShouldExit>
|
||||||
|
bool Read( void* buf, int len, int timeout, ShouldExit exitCb )
|
||||||
|
{
|
||||||
|
auto cbuf = (char*)buf;
|
||||||
|
while( len > 0 )
|
||||||
|
{
|
||||||
|
if( exitCb() ) return false;
|
||||||
|
if( !ReadImpl( cbuf, len, timeout ) ) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ReadRaw( void* buf, int len, int timeout );
|
bool ReadRaw( void* buf, int len, int timeout );
|
||||||
bool HasData();
|
bool HasData();
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
@ -39,6 +52,8 @@ private:
|
|||||||
int RecvBuffered( void* buf, int len, int timeout );
|
int RecvBuffered( void* buf, int len, int timeout );
|
||||||
int Recv( void* buf, int len, int timeout );
|
int Recv( void* buf, int len, int timeout );
|
||||||
|
|
||||||
|
bool ReadImpl( char*& buf, int& len, int timeout );
|
||||||
|
|
||||||
char* m_buf;
|
char* m_buf;
|
||||||
char* m_bufPtr;
|
char* m_bufPtr;
|
||||||
int m_sock;
|
int m_sock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user