Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JSocketBlocking.hh
Go to the documentation of this file.
1#ifndef __JNET__JSOCKETBLOCKING__
2#define __JNET__JSOCKETBLOCKING__
3
4#include "JNet/JTCPSocket.hh"
5
6
7/**
8 * \author mdejong
9 */
10
11namespace JNET {}
12namespace JPP { using namespace JNET; }
13
14namespace JNET {
15
16
17 /**
18 * Blocking socket I/O.
19 * This class implements blocking I/O regardless of the configuration
20 * of the socket (see method JSocket::setNonBlocking()).
21 */
23 public JTCPSocket
24 {
25 public:
26 /**
27 * Default constructor.
28 */
32
33
34 /**
35 * Constructor.
36 *
37 * \param socket socket
38 */
39 JSocketBlocking(const JTCPSocket& socket) :
40 JTCPSocket(socket)
41 {}
42
43
44
45 /**
46 * Read data from socket.
47 *
48 * \param buffer buffer
49 * \param length number of bytes to read
50 * \return number of bytes read
51 */
52 int read(char* buffer, const int length) override
53 {
54 char* data = buffer;
55 int size = length;
56
57 while (size != 0) {
58
59 const int pos = JSocket::read(data, size);
60
61 if (pos != 0) {
62 data += pos;
63 size -= pos;
64 } else {
65 in_avail(1);
66 }
67 }
68
69 return length - size;
70 }
71
72
73 /**
74 * Write data to socket.
75 *
76 * \param buffer buffer
77 * \param length number of bytes to write
78 * \return number of bytes written
79 */
80 int write(const char* buffer, const int length) override
81 {
82 const char* data = buffer;
83 int size = length;
84
85 while (size != 0) {
86
87 const int pos = JSocket::write(data, size);
88
89 if (pos != 0) {
90 data += pos;
91 size -= pos;
92 } else {
93 out_avail(1);
94 }
95 }
96
97 return length - size;
98 }
99 };
100}
101
102#endif
bool out_avail(JTimeval timeout=JTimeval::min()) const
Check availability of output.
Definition JFile.hh:119
bool in_avail(JTimeval timeout=JTimeval::min()) const
Check availability of input.
Definition JFile.hh:106
Blocking socket I/O.
int read(char *buffer, const int length) override
Read data from socket.
JSocketBlocking()
Default constructor.
int write(const char *buffer, const int length) override
Write data to socket.
JSocketBlocking(const JTCPSocket &socket)
Constructor.
virtual int read(char *buffer, const int length) override
Read data from socket.
Definition JSocket.hh:198
virtual int write(const char *buffer, const int length) override
Write data to socket.
Definition JSocket.hh:237
TCP socket.
Definition JTCPSocket.hh:30
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).