00001 // -*- C++ -*- 00002 // 00014 // ***** BEGIN LICENSE BLOCK ***** 00015 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00016 // 00017 // The contents of this file are subject to the Mozilla Public License 00018 // Version 1.1 (the "License"); you may not use this file except in 00019 // compliance with the License. You may obtain a copy of the License at 00020 // http://www.mozilla.org/MPL/ 00021 // 00022 // Software distributed under the License is distributed on an "AS IS" 00023 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00024 // the License for the specific language governing rights and limitations 00025 // under the License. 00026 // 00027 // The Original Code is the consmgr network/serial-line monitoring package. 00028 // 00029 // The Initial Developer of the Original Code is Chris P. Ross. 00030 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00031 // the Initial Developer. All Rights Reserved. 00032 // 00033 // Contributor(s): 00034 // 00035 // Alternatively, the contents of this file may be used under the terms of 00036 // either the GNU General Public License Version 2 or later (the "GPL"), or 00037 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00038 // in which case the provisions of the GPL or the LGPL are applicable instead 00039 // of those above. If you wish to allow use of your version of this file only 00040 // under the terms of either the GPL or the LGPL, and not to allow others to 00041 // use your version of this file under the terms of the MPL, indicate your 00042 // decision by deleting the provisions above and replace them with the notice 00043 // and other provisions required by the GPL or the LGPL. If you do not delete 00044 // the provisions above, a recipient may use your version of this file under 00045 // the terms of any one of the MPL, the GPL or the LGPL. 00046 // 00047 // ***** END LICENSE BLOCK ***** 00048 00049 #ifndef __SOCKLISTENER_H 00050 #define __SOCKLISTENER_H 00051 00052 extern "C" { 00053 #include <sys/types.h> 00054 #include <netdb.h> 00055 #include <sys/socket.h> 00056 } 00057 00058 // Get the base class 00059 #include "listener.h" 00060 00061 #include "connector.h" 00062 #include "sockaddr.h" 00063 00064 00070 class SocketListener : public Listener { 00071 public: 00072 SocketListener(SocketAddressP &address); 00073 00074 virtual ~SocketListener(); 00075 00076 virtual ConnectorP listen_for_incoming(); 00077 00080 virtual void disconnect(); 00081 00082 std::string class_name(void) const { return "SocketListener"; } 00083 std::string get_id(void) const; 00084 00085 protected: 00089 virtual int make_incoming_socket(void); 00090 00092 SocketAddressP sock_addr; 00093 00094 // This is the fd the accept is done on, to return the fd's that 00095 // are the actual connections... (protected by 'mutex') Only used 00096 // when awaiting incoming connections with listen_for_connections() 00097 // and listen_for_incoming()... 00098 int sock_fd; 00099 00102 pthread_mutex_t mutex; 00103 }; 00104 00105 #endif /* __SOCKLISTENER_H */