Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ACE_IOS_STREAM_HANDLER_H
00010 #define ACE_IOS_STREAM_HANDLER_H
00011
00012 #include "ace/pre.h"
00013
00014 #include "ace/config-all.h"
00015
00016 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00017 # pragma once
00018 #endif
00019
00020 #include "ace/Svc_Handler.h"
00021 #include "ace/Reactor_Notification_Strategy.h"
00022
00023 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00024
00025 namespace ACE
00026 {
00027 namespace IOS
00028 {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 template <ACE_PEER_STREAM_1, ACE_SYNCH_DECL>
00040 class StreamHandler
00041 : public ACE_Svc_Handler<ACE_PEER_STREAM, ACE_SYNCH_USE>
00042 {
00043 public:
00044
00045 typedef StreamHandler<ACE_PEER_STREAM, ACE_SYNCH_USE> this_type;
00046 typedef ACE_Svc_Handler<ACE_PEER_STREAM, ACE_SYNCH_USE> base_type;
00047 typedef ACE_Message_Queue<ACE_SYNCH_USE> mq_type;
00048
00049
00050 StreamHandler (const ACE_Synch_Options &synch_options = ACE_Synch_Options::defaults,
00051 ACE_Thread_Manager *thr_mgr = 0,
00052 mq_type *mq = 0,
00053 ACE_Reactor *reactor = ACE_Reactor::instance ());
00054
00055
00056 virtual ~StreamHandler ();
00057
00058
00059 virtual int open (void * = 0);
00060
00061
00062 virtual int close (u_long flags = 0);
00063
00064
00065
00066 virtual int handle_input (ACE_HANDLE);
00067
00068
00069
00070 virtual int handle_output (ACE_HANDLE);
00071
00072
00073 int read_from_stream (void * buf, size_t length, u_short char_size);
00074
00075
00076 int write_to_stream (const void * buf, size_t length, u_short char_size);
00077
00078
00079 bool is_connected () const;
00080
00081
00082 bool using_reactor () const;
00083
00084 private:
00085 enum
00086 {
00087 MAX_INPUT_SIZE = 4096
00088 };
00089
00090
00091
00092
00093 int handle_output_i (ACE_Time_Value* timeout = 0);
00094
00095
00096
00097
00098 int handle_input_i (size_t rdlen, ACE_Time_Value* timeout = 0);
00099
00100
00101 int process_input (char* buf,
00102 size_t& char_length,
00103 u_short char_size,
00104 ACE_Time_Value* timeout);
00105
00106
00107 bool use_timeout () const;
00108
00109
00110 bool char_in_queue (u_short char_size);
00111
00112 bool connected_;
00113 ACE_Synch_Options sync_opt_;
00114 bool send_timeout_;
00115 bool receive_timeout_;
00116 ACE_Reactor_Notification_Strategy notification_strategy_;
00117
00118 class NotificationStrategyGuard
00119 {
00120 public:
00121 NotificationStrategyGuard (this_type& queue_owner,
00122 ACE_Reactor_Notification_Strategy* ns)
00123 : queue_owner_ (queue_owner)
00124 {
00125 this->queue_owner_.msg_queue ()->notification_strategy (ns);
00126 }
00127 ~NotificationStrategyGuard ()
00128 {
00129 this->queue_owner_.msg_queue ()->notification_strategy (0);
00130 }
00131 private:
00132 this_type& queue_owner_;
00133 };
00134 };
00135
00136 typedef StreamHandler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> SockStreamHandler;
00137 }
00138 }
00139
00140 ACE_END_VERSIONED_NAMESPACE_DECL
00141
00142 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00143 #include "ace/INet/StreamHandler.cpp"
00144 #endif
00145
00146 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00147 #pragma implementation ("StreamHandler.cpp")
00148 #endif
00149
00150 #include "ace/post.h"
00151 #endif