Robotics Library  0.6.2
Socket.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_HAL_SOCKET_H_
28 #define _RL_HAL_SOCKET_H_
29 
30 #include <string>
31 #include <rl/math/Real.h>
32 
33 #include "Com.h"
34 
35 namespace rl
36 {
37  namespace hal
38  {
39  class Socket : public Com
40  {
41  public:
42  Socket(const ::std::string& host, const unsigned short int& port);
43 
44  virtual ~Socket();
45 
46  void close();
47 
48  ::std::string getHost() const;
49 
50  unsigned short int getPort() const;
51 
52  virtual void open() = 0;
53 
54  ::std::size_t read(void* buf, const ::std::size_t& count);
55 
56  ::std::size_t select(const bool& read, const bool& write, const ::rl::math::Real& timeout);
57 
58  ::std::size_t write(const void* buf, const ::std::size_t& count);
59 
60  protected:
61  void connect(const int& domain, const int& type, const int& protocol);
62 
63  private:
64  ::std::string host;
65 
66  unsigned short int port;
67 
68  int sockfd;
69  };
70  }
71 }
72 
73 #endif // _RL_HAL_SOCKET_H_
rl::hal::Socket
Definition: Socket.h:40
rl::hal::Socket::Socket
Socket(const ::std::string &host, const unsigned short int &port)
Definition: Socket.cpp:52
rl::hal::Socket::getHost
::std::string getHost() const
Definition: Socket.cpp:167
Com.h
rl::hal::Socket::close
void close()
Definition: Socket.cpp:68
rl::hal::Socket::select
::std::size_t select(const bool &read, const bool &write, const ::rl::math::Real &timeout)
Definition: Socket.cpp:209
rl::hal::Socket::~Socket
virtual ~Socket()
Definition: Socket.cpp:59
rl::hal::Socket::port
unsigned short int port
Definition: Socket.h:66
rl::hal::Socket::getPort
unsigned short int getPort() const
Definition: Socket.cpp:173
rl::hal::Com
Definition: Com.h:35
rl::hal::Socket::open
virtual void open()=0
rl::hal::Socket::read
::std::size_t read(void *buf, const ::std::size_t &count)
Definition: Socket.cpp:179
Real.h
rl::hal::Socket::write
::std::size_t write(const void *buf, const ::std::size_t &count)
Definition: Socket.cpp:274
rl::hal::Socket::connect
void connect(const int &domain, const int &type, const int &protocol)
Definition: Socket.cpp:92
rl::math::Real
double Real
Definition: Real.h:34
rl::hal::Socket::host
::std::string host
Definition: Socket.h:64
rl::hal::Socket::sockfd
int sockfd
Definition: Socket.h:68
rl
Definition: Ati.cpp:35