SDL Window Engine  20200905
swe_streamnet.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_STREAMNET_
24 #define _SWE_STREAMNET_
25 
26 #ifndef SWE_DISABLE_NETWORK
27 #include "swe_serialize.h"
28 
30 namespace SWE
31 {
32 
33  class StreamNetwork : public StreamBase
34  {
35  StreamNetwork(const StreamNetwork &) {}
36  StreamNetwork & operator= (const StreamNetwork &) { return *this; }
37 
38  size_t tell(void) const override { return 0; }
39  bool skip(size_t len) const override { return false; }
40 
41  protected:
42  TCPsocket sd;
43  SDLNet_SocketSet sdset;
44 
45  int recv(char*, int) const;
46  int send(const char*, int);
47 
48  public:
49  StreamNetwork();
50  StreamNetwork(TCPsocket);
51  StreamNetwork(const std::string &, int);
52  ~StreamNetwork();
53 
54  StreamNetwork(StreamNetwork &&) noexcept;
55  StreamNetwork & operator=(StreamNetwork &&) noexcept;
56 
57  static StringList localAddresses(void);
58  static std::pair<std::string, int>
59  peerAddress(TCPsocket);
60  TCPsocket accept(void);
61 
62  bool isValid(void) const { return sd; }
63  bool open(TCPsocket);
64  bool connect(const std::string &, int);
65  bool listen(int port);
66  void close(void);
67  bool ready(u32 timeout = 100 /* ms */) const;
68 
69  int get8(void) const override;
70  int getBE16(void) const override;
71  int getLE16(void) const override;
72  int getBE32(void) const override;
73  int getLE32(void) const override;
74  s64 getBE64(void) const override;
75  s64 getLE64(void) const override;
76  BinaryBuf get(size_t = 0 /* all data */) const override;
77 
78  void put8(char) override;
79  void putBE64(u64) override;
80  void putLE64(u64) override;
81  void putBE32(u32) override;
82  void putLE32(u32) override;
83  void putBE16(u16) override;
84  void putLE16(u16) override;
85  void put(const char*, size_t) override;
86  };
87 
88 } // SWE
89 #endif
90 #endif
пространство SWE.
Definition: swe_binarybuf.cpp:30
класс списка строк
Definition: swe_cstring.h:36
класс бинарного массива
Definition: swe_binarybuf.h:35
Definition: swe_streamnet.h:33
Definition: swe_serialize.h:44