return *peer_addr;
}
-unsigned ClientSocket::do_write(const char *buf, unsigned size)
+size_t ClientSocket::do_write(const char *buf, size_t size)
{
check_access(IO::M_WRITE);
if(!connected)
return check_sys_error(::send(priv->handle, buf, size, 0), "send");
}
-unsigned ClientSocket::do_read(char *buf, unsigned size)
+size_t ClientSocket::do_read(char *buf, size_t size)
{
check_access(IO::M_READ);
if(!connected)
if(size==0)
return 0;
- unsigned ret = check_sys_error(::recv(priv->handle, buf, size, 0), "recv");
+ size_t ret = check_sys_error(::recv(priv->handle, buf, size, 0), "recv");
if(ret==0 && !eof_flag)
{
eof_flag = true;
const SockAddr &get_peer_address() const;
protected:
- virtual unsigned do_write(const char *, unsigned);
- virtual unsigned do_read(char *, unsigned);
+ virtual std::size_t do_write(const char *, std::size_t);
+ virtual std::size_t do_read(char *, std::size_t);
};
} // namespace Net
handshake_status = 1;
}
-void Communicator::send_data(unsigned size)
+void Communicator::send_data(size_t size)
{
if(!good)
throw sequence_error("connection aborted");
{
if(in_end==in_buf+buf_size)
{
- unsigned used = in_end-in_begin;
+ size_t used = in_end-in_begin;
memmove(in_buf, in_begin, used);
in_begin = in_buf;
in_end = in_begin+used;
shake.hash = protocol.get_hash();
HandshakeProtocol hsproto;
- unsigned size = hsproto.serialize(shake, out_buf, buf_size);
+ size_t size = hsproto.serialize(shake, out_buf, buf_size);
socket.write(out_buf, size);
}
const Protocol &protocol;
ReceiverBase &receiver;
int handshake_status;
- unsigned buf_size;
+ std::size_t buf_size;
char *in_buf;
char *in_begin;
char *in_end;
void send(const P &);
private:
- void send_data(unsigned);
+ void send_data(std::size_t);
void data_available();
bool receive_packet(const Protocol &, ReceiverBase &);
return true;
}
-unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr &addr)
+size_t DatagramSocket::sendto(const char *buf, size_t size, const SockAddr &addr)
{
if(size==0)
return 0;
return check_sys_error(::sendto(priv->handle, buf, size, 0, reinterpret_cast<const sockaddr *>(&sa.addr), sa.size), "sendto");
}
-unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&from_addr)
+size_t DatagramSocket::recvfrom(char *buf, size_t size, SockAddr *&from_addr)
{
if(size==0)
return 0;
SockAddr::SysAddr sa;
- unsigned ret = check_sys_error(::recvfrom(priv->handle, buf, size, 0, reinterpret_cast<sockaddr *>(&sa.addr), &sa.size), "recvfrom");
+ size_t ret = check_sys_error(::recvfrom(priv->handle, buf, size, 0, reinterpret_cast<sockaddr *>(&sa.addr), &sa.size), "recvfrom");
from_addr = SockAddr::new_from_sys(sa);
return ret;
virtual bool connect(const SockAddr &);
virtual bool poll_connect(const Time::TimeDelta &) { return false; }
- unsigned sendto(const char *, unsigned, const SockAddr &);
- unsigned recvfrom(char *, unsigned, SockAddr *&);
+ std::size_t sendto(const char *, std::size_t, const SockAddr &);
+ std::size_t recvfrom(char *, std::size_t, SockAddr *&);
};
} // namespace Net
return *get_item(packet_id_defs, id);
}
-unsigned Protocol::dispatch(ReceiverBase &rcv, const char *buf, unsigned size) const
+size_t Protocol::dispatch(ReceiverBase &rcv, const char *buf, size_t size) const
{
PacketHeader header;
buf = header_def.deserialize(header, buf, buf+size);
return ptr-buf;
}
-unsigned Protocol::get_packet_size(const char *buf, unsigned size) const
+size_t Protocol::get_packet_size(const char *buf, size_t size) const
{
if(size<4)
return 0;
throw buffer_error("overflow");
const char *ptr = reinterpret_cast<const char *>(&value)+sizeof(T);
- for(unsigned i=0; i<sizeof(T); ++i)
+ for(size_t i=0; i<sizeof(T); ++i)
*buf++ = *--ptr;
return buf;
throw buffer_error("underflow");
char *ptr = reinterpret_cast<char *>(&value)+sizeof(T);
- for(unsigned i=0; i<sizeof(T); ++i)
+ for(size_t i=0; i<sizeof(T); ++i)
*--ptr = *buf++;
return buf;
public:
template<typename P>
- unsigned serialize(const P &, char *, unsigned) const;
+ std::size_t serialize(const P &, char *, std::size_t) const;
- unsigned get_packet_size(const char *, unsigned) const;
- unsigned dispatch(ReceiverBase &, const char *, unsigned) const;
+ std::size_t get_packet_size(const char *, std::size_t) const;
+ std::size_t dispatch(ReceiverBase &, const char *, std::size_t) const;
UInt64 get_hash() const;
}
template<typename P>
-unsigned Protocol::serialize(const P &pkt, char *buf, unsigned size) const
+std::size_t Protocol::serialize(const P &pkt, char *buf, std::size_t size) const
{
const PacketTypeDef<P> &pdef = get_packet_by_class<P>();
if(!pdef.get_id())
Socket(af, type, proto)
{ }
-unsigned ServerSocket::do_write(const char *, unsigned)
+size_t ServerSocket::do_write(const char *, size_t)
{
throw logic_error("can't write to ServerSocket");
}
-unsigned ServerSocket::do_read(char *, unsigned)
+size_t ServerSocket::do_read(char *, size_t)
{
throw logic_error("can't read from ServerSocket");
}
virtual ClientSocket *accept() = 0;
protected:
- virtual unsigned do_write(const char *, unsigned);
- virtual unsigned do_read(char *, unsigned);
+ virtual std::size_t do_write(const char *, std::size_t);
+ virtual std::size_t do_read(char *, std::size_t);
};
} // namespace Net
int get_option(int, int, void *, socklen_t *);
};
-unsigned check_sys_error(int, const char *);
+std::size_t check_sys_error(std::make_signed<std::size_t>::type, const char *);
bool check_sys_connect_error(int);
} // namespace Net
#include "socket.h"
#include "socket_private.h"
+using namespace std;
+
namespace Msp {
namespace Net {
}
-unsigned check_sys_error(int ret, const char *func)
+size_t check_sys_error(make_signed<size_t>::type ret, const char *func)
{
if(ret<0)
{
#include "socket.h"
#include "socket_private.h"
+using namespace std;
+
namespace {
class WinSockHelper
}
-unsigned check_sys_error(int ret, const char *func)
+size_t check_sys_error(make_signed<size_t>::type ret, const char *func)
{
if(ret<0)
{