2 * Copyright 2011, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
10 //#define TRACE_SOCKET
12 # define TRACE(x...) printf(x)
14 # define TRACE(x...) ;
23 BSocket::BSocket(const BNetworkAddress
& peer
, bigtime_t timeout
)
25 Connect(peer
, timeout
);
29 BSocket::BSocket(const BSocket
& other
)
31 BAbstractSocket(other
)
42 BSocket::Bind(const BNetworkAddress
& local
)
44 return BAbstractSocket::Bind(local
, SOCK_STREAM
);
49 BSocket::Connect(const BNetworkAddress
& peer
, bigtime_t timeout
)
51 return BAbstractSocket::Connect(peer
, SOCK_STREAM
, timeout
);
55 // #pragma mark - BDataIO implementation
59 BSocket::Read(void* buffer
, size_t size
)
61 ssize_t bytesReceived
= recv(Socket(), buffer
, size
, 0);
62 if (bytesReceived
< 0) {
63 TRACE("%p: BSocket::Read() error: %s\n", this, strerror(errno
));
72 BSocket::Write(const void* buffer
, size_t size
)
74 ssize_t bytesSent
= send(Socket(), buffer
, size
, 0);
76 TRACE("%p: BSocket::Write() error: %s\n", this, strerror(errno
));
84 // #pragma mark - private
88 BSocket::_SetTo(int fd
, const BNetworkAddress
& local
,
89 const BNetworkAddress
& peer
)
98 TRACE("%p: accepted from %s to %s\n", this, local
.ToString().c_str(),
99 peer
.ToString().c_str());