[10134] MaNGOS 0.16 release.
[getmangos.git] / src / realmd / BufferedSocket.h
blob57ee22171c564c6ed412675c016f6643a3d64cd7
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /** \file
20 \ingroup realmd
23 #ifndef _BUFFEREDSOCKET_H_
24 #define _BUFFEREDSOCKET_H_
26 #include <ace/Basic_Types.h>
27 #include <ace/Synch_Traits.h>
28 #include <ace/Svc_Handler.h>
29 #include <ace/SOCK_Stream.h>
30 #include <ace/Message_Block.h>
31 #include <ace/Basic_Types.h>
33 #include <string>
35 class BufferedSocket: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
37 protected:
38 typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
40 virtual void OnRead(void) { }
41 virtual void OnAccept(void) { }
42 virtual void OnClose(void) { }
44 public:
45 BufferedSocket(void);
46 virtual ~BufferedSocket(void);
48 size_t recv_len(void) const;
49 bool recv_soft(char *buf, size_t len);
50 bool recv(char *buf, size_t len);
51 void recv_skip(size_t len);
53 bool send(const char *buf, size_t len);
55 const std::string& get_remote_address(void) const;
57 virtual int open(void *);
59 void close_connection(void);
61 virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);
62 virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE);
64 virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE,
65 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
67 private:
68 ssize_t noblk_send(ACE_Message_Block &message_block);
70 private:
71 ACE_Message_Block input_buffer_;
73 protected:
74 std::string remote_address_;
78 #endif /* _BUFFEREDSOCKET_H_ */