1 #ifndef __JNET__JSOCKET__
2 #define __JNET__JSOCKET__
4 #include <sys/socket.h>
6 #include <netinet/tcp.h>
7 #include <netinet/in.h>
27 namespace 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));
161 return getOption<int>(SOL_SOCKET, SO_RCVBUF);
172 setOption(SOL_SOCKET, SO_SNDBUF,
int(size));
183 return getOption<int>(SOL_SOCKET, SO_SNDBUF);
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);
void setReuseAddress(const bool on)
Set reuse address.
int getSendBufferSize() const
Get send buffer size.
bool getReuseAddress() const
Get reuse address.
void setSendBufferSize(const int size)
Set send buffer size.
int getReceiveBufferSize() const
Set receive buffer size.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
virtual int read(char *buffer, const int length)
Read data from file.
then set_variable PMT_FILE set_variable DAQ_FILE set_variable OUTPUT_FILE set_variable DETECTOR else fatal Wrong number of arguments fi JPrintTree f $DAQ_FILE type
virtual int read(char *buffer, const int length) override
Read data from socket.
bool getKeepAlive() const
Get keep alive of socket.
The JFile class extends the JAbstractFile class.
int getFileDescriptor() const
Get file descriptor.
int shutdown()
Shut down socket.
The JSocketAddress class encapsulates the sockaddr_in data structure.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
static const long long int MEGABYTE
Number of bytes in a kilo-byte.
JSocket(const int domain, const int type, const int protocol=0)
Constructor.
void setReceiveBufferSize(const int size)
Set receive buffer size.
T getOption(const int level, const int option) const
Get socket option.
static const long long int GIGABYTE
Number of bytes in a mega-byte.
void setKeepAlive(const bool on)
Set keep alive of socket.
JSocket()
Default constructor.
static const int getDefaultBufferSize()
Default socket buffer size to be used on this system.
void setFamily(const int family)
Set family.
virtual int write(const char *buffer, const int length) override
Write data to socket.
void setOption(const int level, const int option, const T value)
Set socket option.
virtual int write(const char *buffer, const int length)
Write data to file.