socket.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2022, Autonics Co.,Ltd.
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
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 *
17 * * Neither the name of the Autonics Co.,Ltd nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 
36 
37 #ifndef SOCKET_HPP
38 #define SOCKET_HPP
39 
40 #include <pthread.h>
41 #include <vector>
42 #include <queue>
43 
44 #include <sys/socket.h>
45 #include <arpa/inet.h>
46 #include <string>
47 #include <iostream>
48 #include <unistd.h>
49 #include <string.h>
50 #include <stdlib.h>
51 #include <errno.h>
52 
53 class Socket
54 {
55  public:
56  Socket();
57  ~Socket();
58 
59  int clientOpen(std::string addr, std::string port);
60  int clientOpen(void);
61  int32_t clientRead(unsigned char* buffer, uint16_t buf_size);
62  int32_t clientWrite(unsigned char* buffer, uint16_t buf_size);
63 
64  int tryReconnection(void);
65 
66  friend void* readCallback(void* arg);
67 
68  int getServerSocket(void);
69  bool getConnected(void);
70 
71  bool getRcvTimeout(void);
72  bool getRcvError(void);
73 
74  void setRcvTimeout(bool flag);
75  void setRcvError(bool flag);
76 
77  bool getPthreadRunning(void);
78 
79  std::queue<std::vector<unsigned char> > recvQueue;
80 
81  private:
82  void putBufToMsg(unsigned char* buf, uint16_t size);
83 
84  sockaddr_in m_server_addr_;
85  pthread_t pthrd_id_;
86  std::string addr_st_ ;
87  std::string port_num_st_;
88 
93  bool rcv_error_;
94 };
95 
96 #endif
Socket::rcv_timeout_
bool rcv_timeout_
Definition: socket.hpp:92
Socket::m_connected_
bool m_connected_
Definition: socket.hpp:91
Socket::tryReconnection
int tryReconnection(void)
Definition: socket.cpp:110
Socket::setRcvError
void setRcvError(bool flag)
Definition: socket.cpp:103
Socket::getPthreadRunning
bool getPthreadRunning(void)
Definition: socket.cpp:82
Socket
Definition: socket.hpp:53
Socket::Socket
Socket()
Definition: socket.cpp:41
Socket::m_server_sock_
int m_server_sock_
Definition: socket.hpp:89
Socket::addr_st_
std::string addr_st_
Definition: socket.hpp:86
Socket::pthrd_id_
pthread_t pthrd_id_
Definition: socket.hpp:85
Socket::clientOpen
int clientOpen(void)
Socket::getRcvTimeout
bool getRcvTimeout(void)
Definition: socket.cpp:88
Socket::getRcvError
bool getRcvError(void)
Definition: socket.cpp:93
Socket::clientRead
int32_t clientRead(unsigned char *buffer, uint16_t buf_size)
Definition: socket.cpp:346
Socket::clientWrite
int32_t clientWrite(unsigned char *buffer, uint16_t buf_size)
Definition: socket.cpp:368
Socket::getServerSocket
int getServerSocket(void)
Definition: socket.cpp:72
Socket::m_server_addr_
sockaddr_in m_server_addr_
Definition: socket.hpp:84
Socket::putBufToMsg
void putBufToMsg(unsigned char *buf, uint16_t size)
Definition: socket.cpp:137
Socket::rcv_error_
bool rcv_error_
Definition: socket.hpp:93
Socket::readCallback
friend void * readCallback(void *arg)
Definition: socket.cpp:150
Socket::pthread_running_
bool pthread_running_
Definition: socket.hpp:90
Socket::setRcvTimeout
void setRcvTimeout(bool flag)
Definition: socket.cpp:98
Socket::port_num_st_
std::string port_num_st_
Definition: socket.hpp:87
Socket::recvQueue
std::queue< std::vector< unsigned char > > recvQueue
Definition: socket.hpp:79
Socket::~Socket
~Socket()
Definition: socket.cpp:53
Socket::getConnected
bool getConnected(void)
Definition: socket.cpp:77


lsc_ros_driver
Author(s): Autonics-lidar
autogenerated on Sat Jan 14 2023 03:18:24