Apollo 10.0
自动驾驶开放平台
tcp_stream.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19namespace apollo {
20namespace drivers {
21namespace gnss {
22
23class TcpStream : public Stream {
24 typedef uint16_t be16_t;
25 typedef uint32_t be32_t;
26
27 public:
28 TcpStream(const char *address, uint16_t port, uint32_t timeout_usec,
29 bool auto_reconnect = true);
30 ~TcpStream();
31
32 virtual bool Connect();
33 virtual bool Disconnect();
34 virtual size_t read(uint8_t *buffer, size_t max_length);
35 virtual size_t write(const uint8_t *data, size_t length);
36
37 private:
38 bool Reconnect();
39 bool Readable(uint32_t timeout_us);
40 TcpStream() {}
41 void open();
42 void close();
43 bool InitSocket();
44 be16_t peer_port_ = 0;
45 be32_t peer_addr_ = 0;
46 uint32_t timeout_usec_ = 0;
47 int sockfd_ = -1;
48 int errno_ = 0;
49 bool auto_reconnect_ = false;
50};
51
52} // namespace gnss
53} // namespace drivers
54} // namespace apollo
virtual size_t read(uint8_t *buffer, size_t max_length)
virtual size_t write(const uint8_t *data, size_t length)
class register implement
Definition arena_queue.h:37