OrocosComponentLibrary  2.9.0
socket.hpp
1 /***************************************************************************
2 
3  Socket.h - Small socket wrapper
4  -------------------
5  begin : Fri Aug 4 2006
6  copyright : (C) 2006 Bas Kemper
7  email : kst@ <my name> .be
8 
9  ***************************************************************************
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU Lesser General Public *
12  * License as published by the Free Software Foundation; either *
13  * version 2.1 of the License, or (at your option) any later version. *
14  * *
15  * This library is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18  * Lesser General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU Lesser General Public *
21  * License along with this library; if not, write to the Free Software *
22  * Foundation, Inc., 59 Temple Place, *
23  * Suite 330, Boston, MA 02111-1307 USA *
24  * *
25  ***************************************************************************/
26 #ifndef ORO_COMP_SOCKET_H
27 #define ORO_COMP_SOCKET_H
28 #include <iostream>
29 
30 namespace {
31  class sockbuf;
32 };
33 
34 namespace OCL {
35 namespace TCP {
36  class Socket : public std::ostream {
37  friend class ::sockbuf;
38  private:
42  int socket;
43 
52  bool lineAvailable();
53 
58  void checkBufferOverflow();
59 
63  void rawClose();
64 
68  /* buflength should be at least msglength * 2 in order to avoid problems with memcpy! */
69  #define BUFLENGTH 2000
70  char buffer[BUFLENGTH];
71  int begin;
72  int ptrpos;
73  int end;
74 
75  public:
81  Socket( int socketID );
82  ~Socket();
83 
87  bool isValid() const;
88 
92  bool dataAvailable();
93 
97  std::string readLine();
98 
102  void close();
103  };
104 };
105 };
106 #endif
void close()
Close the connection.
Definition: socket.cpp:278
Socket(int socketID)
Create an incoming server socket.
Definition: socket.cpp:141
The Orocos Component Library.
Definition: Component.hpp:43
std::string readLine()
Read a line from the socket.
Definition: socket.cpp:222
bool isValid() const
Check wether the state of the socket is valid or not.
Definition: socket.cpp:156
bool dataAvailable()
Check wether there is new data available.
Definition: socket.cpp:161