1#ifndef __JNET__JSOCKET__
2#define __JNET__JSOCKET__
6#include <netinet/tcp.h>
27namespace JPP {
using namespace JNET; }
60 const int protocol = 0) :
61 JFile(socket(domain, type, protocol))
106 setOption(SOL_SOCKET, SO_KEEPALIVE,
int(on ? 1 : 0));
117 return (getOption<int>(SOL_SOCKET, SO_KEEPALIVE) == 1);
128 setOption(SOL_SOCKET, SO_REUSEADDR,
int(on ? 1 : 0));
139 return (getOption<int>(SOL_SOCKET, SO_REUSEADDR) == 1);
150 setOption(SOL_SOCKET, SO_RCVBUF,
int(size));
172 setOption(SOL_SOCKET, SO_SNDBUF,
int(size));
198 virtual int read(
char* buffer,
const int length)
override
206 }
else if (pos < 0) {
237 virtual int write(
const char* buffer,
const int length)
override
245 }
else if (pos < 0) {
274 void setOption(
const int level,
const int option,
const T value)
276 socklen_t size =
sizeof(T);
295 socklen_t size =
sizeof(T);
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
int getFileDescriptor() const
Get file descriptor.
The JFile class extends the JAbstractFile class.
virtual int write(const char *buffer, const int length)
Write data to file.
virtual int read(char *buffer, const int length)
Read data from file.
The JSocketAddress class encapsulates the sockaddr_in data structure.
void setFamily(const int family)
Set family.
void setReceiveBufferSize(const int size)
Set receive buffer size.
void setOption(const int level, const int option, const T value)
Set socket option.
virtual int read(char *buffer, const int length) override
Read data from socket.
T getOption(const int level, const int option) const
Get socket option.
JSocket()
Default constructor.
int getSendBufferSize() const
Get send buffer size.
JSocket(const int domain, const int type, const int protocol=0)
Constructor.
bool getKeepAlive() const
Get keep alive of socket.
int getReceiveBufferSize() const
Set receive buffer size.
static const int getDefaultBufferSize()
Default socket buffer size to be used on this system.
int shutdown()
Shut down socket.
bool getReuseAddress() const
Get reuse address.
void setReuseAddress(const bool on)
Set reuse address.
void setKeepAlive(const bool on)
Set keep alive of socket.
void setSendBufferSize(const int size)
Set send buffer size.
virtual int write(const char *buffer, const int length) override
Write data to socket.
static const long long int GIGABYTE
Number of bytes in a mega-byte.
static const long long int MEGABYTE
Number of bytes in a kilo-byte.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).