libsocket
streamclient.hpp
Go to the documentation of this file.
1 #ifndef LIBSOCKET_STREAMCLIENT_H_4EF38CC5CAD740E6B7A55BCF4C48CCFA
2 #define LIBSOCKET_STREAMCLIENT_H_4EF38CC5CAD740E6B7A55BCF4C48CCFA
3 
4 #include <string>
5 #include "socket.hpp"
6 
13 /*
14  The committers of the libsocket project, all rights reserved
15  (c) 2012, dermesser <lbo@spheniscida.de>
16 
17  Redistribution and use in source and binary forms, with or without
18  modification, are permitted provided that the following conditions are met:
19 
20  1. Redistributions of source code must retain the above copyright notice,
21  this list of conditions and the following disclaimer.
22  2. Redistributions in binary form must reproduce the above copyright notice,
23  this list of conditions and the following disclaimer in the documentation
24  and/or other materials provided with the distribution.
25 
26  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS “AS IS” AND ANY
27  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
30  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 
37 */
38 
39 namespace libsocket {
40 using std::string;
41 class dgram_over_stream;
42 
52 class stream_client_socket : public virtual socket {
53  protected:
54  bool shut_rd;
55  bool shut_wr;
57 
59  public:
63  : socket(std::move(other)), shut_rd(false), shut_wr(false) {}
64 
65  ssize_t snd(const void* buf, size_t len, int flags = 0); // flags: send()
66  ssize_t rcv(void* buf, size_t len, int flags = 0); // flags: recv()
67 
69  const char* str);
71  const string& str);
73  string& dest);
74  friend class dgram_over_stream;
75 
76  void shutdown(int method = LIBSOCKET_WRITE);
77 };
81 } // namespace libsocket
82 #endif
Contains libsocket elements.
Definition: dgramclient.hpp:41
ssize_t rcv(void *buf, size_t len, int flags=0)
Receive data from socket.
socket is the base class of every other libsocket++ object.
Definition: socket.hpp:71
friend stream_client_socket & operator<<(stream_client_socket &sock, const char *str)
Send data to socket.
stream_client_socket()
Void constructor.
ssize_t snd(const void *buf, size_t len, int flags=0)
Send data to socket.
Wraps a stream socket and provides a message-based API on top of it.
Generic socket for active stream sockets (TCP client sockets, UNIX Stream clients)
void shutdown(int method=LIBSOCKET_WRITE)
Shut a socket down.
friend stream_client_socket & operator>>(stream_client_socket &sock, string &dest)
Receive data from socket to a string.