1 #ifndef __JNET__JSOCKET__
2 #define __JNET__JSOCKET__
4 #include <sys/socket.h>
6 #include <netinet/tcp.h>
7 #include <netinet/in.h>
25 namespace JPP {
using namespace JNET; }
58 const int protocol = 0) :
59 JFile(socket(domain, type, protocol))
89 setOption(SOL_SOCKET, SO_KEEPALIVE,
int(on ? 1 : 0));
100 return (getOption<int>(SOL_SOCKET, SO_KEEPALIVE) == 1);
111 setOption(SOL_SOCKET, SO_REUSEADDR,
int(on ? 1 : 0));
122 return (getOption<int>(SOL_SOCKET, SO_REUSEADDR) == 1);
133 setOption(SOL_SOCKET, SO_RCVBUF,
int(size));
144 return getOption<int>(SOL_SOCKET, SO_RCVBUF);
155 setOption(SOL_SOCKET, SO_SNDBUF,
int(size));
166 return getOption<int>(SOL_SOCKET, SO_SNDBUF);
181 virtual int read(
char* buffer,
const int length)
override
189 }
else if (pos < 0) {
220 virtual int write(
const char* buffer,
const int length)
override
228 }
else if (pos < 0) {
257 void setOption(
const int level,
const int option,
const T value)
259 socklen_t size =
sizeof(
T);
278 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.
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
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.
void setKeepAlive(const bool on)
Set keep alive of socket.
JSocket()
Default constructor.
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.