a388b0a256fe1f9151180a2a77ad1a6a90ab0c93
[shibboleth/cpp-sp.git] / shib-target / RPCListener.h
1 /*
2  *  Copyright 2001-2005 Internet2
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 /* RPCListener.h - ONC RPC-based Listener implementation
18
19    $Id$
20 */
21
22 #ifndef __RPCListener_h__
23 #define __RPCListener_h__
24
25 #ifdef WIN32
26 # define _CRT_NONSTDC_NO_DEPRECATE 1
27 # define _CRT_SECURE_NO_DEPRECATE 1
28 #endif
29
30 #ifndef FD_SETSIZE
31 # define FD_SETSIZE 1024
32 #endif
33
34 #include <saml/saml.h>  // need this to "prime" the xmlsec-constrained windows.h declaration
35 #include <shib-target/shibrpc.h>
36 #include "internal.h"
37
38 namespace shibtarget {
39
40     class RPCHandlePool;
41     class ServerThread;
42     class RPCListener : public virtual IListener
43     {
44     public:
45         RPCListener(const DOMElement* e);
46         ~RPCListener();
47
48         DDF send(const DDF& in);
49         bool run(bool* shutdown);
50
51         // Implemented by socket-specific subclasses.
52 #ifdef WIN32
53         typedef SOCKET ShibSocket;
54 #else
55         typedef int ShibSocket;
56 #endif
57         virtual bool create(ShibSocket& s) const=0;
58         virtual bool connect(ShibSocket& s) const=0;
59         virtual bool bind(ShibSocket& s, bool force=false) const=0;
60         virtual bool accept(ShibSocket& listener, ShibSocket& s) const=0;
61         virtual bool close(ShibSocket& s) const=0;
62         virtual CLIENT* getClientHandle(ShibSocket& s, u_long program, u_long version) const=0;
63
64     protected:
65         bool log_error() const; // for OS-level errors
66         log4cpp::Category* log;
67     
68     private:
69         mutable RPCHandlePool* m_rpcpool;
70         bool* m_shutdown;
71
72         // Manage child threads
73         friend class ServerThread;
74         std::map<ShibSocket,shibboleth::Thread*> m_children;
75         shibboleth::Mutex* m_child_lock;
76         shibboleth::CondWait* m_child_wait;
77
78         // Primary socket
79         ShibSocket m_socket;
80     };
81 }
82
83 #endif