Continued on fcgi
authorEbersold Andre <aebersol@md2p7zxc.ad001.siemens.net>
Fri, 24 Jun 2022 20:28:12 +0000 (22:28 +0200)
committerEbersold Andre <aebersol@md2p7zxc.ad001.siemens.net>
Fri, 24 Jun 2022 20:28:12 +0000 (22:28 +0200)
aeb/fcgi/fcgi.h
aeb/fcgi/fcgi_handler.h [new file with mode: 0644]
tests/CMakeLists.txt
tests/fcgi_helloworld.cpp [new file with mode: 0644]

index 851136868fd6250519d2376192130ebf61570cf2..54adef679c3b0f35e92dd76099cda9d99a515f93 100644 (file)
@@ -8,7 +8,7 @@ namespace fcgi {
 /**
  *
  */
-template <typename Descriptor,typename InternetProtocol>
+template <typename Descriptor,typename InternetProtocol,typename RequestHandler>
 class acceptor : public basic_socket_acceptor<Descriptor,InternetProtocol>
 {
   public:
@@ -32,12 +32,12 @@ class acceptor : public basic_socket_acceptor<Descriptor,InternetProtocol>
       
       if (s != aeb::net::detail::invalid_socket)
       {
-             m_r = request_handler::ptr(new request_handler(s)) ;
+          m_r = RequestHandler::ptr(new RequestHandler(s)) ;
           m_r->add_ref(); //because request_handler will kill himself 
       }   
     };
   protected:
-    request_handler::ptr m_r;    
+    RequestHandler::ptr m_r;    
 };
 
 
diff --git a/aeb/fcgi/fcgi_handler.h b/aeb/fcgi/fcgi_handler.h
new file mode 100644 (file)
index 0000000..79b1456
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef __FCGI_H__
+#define __FCGI_H__
+
+namespace aeb {
+namespace fcgi {
+
+/**
+ * \brief The handler is reponsible to act as an interface between the 
+ * socket and a request. There is one handler per socket. However, there can
+ * be multiple requests per socket. 
+ * The handler is responsible to dispatch the read message to the right
+ * request handler. Hence this class is more a kind of fcgi message handler
+ * on top of which we will have the Request handler. :w
+ *
+ */
+
+class handler : public event_handler<detail::socket_type,ip::tcp>
+{
+  private:
+      int m_ref;
+  public: 
+    
+    typedef basic_socket_stream<ip::tcp>        Stream;
+    /// aeb::ssl::stream<ip::tcp> ? or detail::socket_type
+    typedef basic_socket_stream<ip::tcp>        SSLStream;
+    
+    typedef aeb::intrusive_ptr<ws_handler>      ptr;
+
+    inline void add_ref() {m_ref++;};
+    
+    inline void release() {
+      if (--m_ref == 0) delete this;
+    };
+    bool available () const;   
+  public:
+    handler(detail::socket_type s);
+  
+    virtual ~handler() ;
+    
+    virtual void onClose(unsigned short _code) ;
+
+    void on_write() ;
+    
+    void on_read() ;
+    
+    void on_accept();
+
+    void io_register();
+    
+    void io_unregister();
+    // reuse handler with a new socket
+    void reuse(aeb::net::detail::socket_type s);
+  
+  protected:
+    handler(const ws_handler &p) ;
+    // Should own an endpoint 
+    long                                m_max_frame_size;
+};
+
+/**
+vim:et:sw=2:ts=2
+ */
+
+
+#endif /*WS_HANDLER_H*/
+}
+}
+
index 58dd56053b20ca60e58409422de51df017facafe..9d16ee86c1d9faaf4cc5bfc6677c3edb1de9c92a 100644 (file)
@@ -9,6 +9,10 @@ ADD_EXECUTABLE(ip4_server
   ip4_server.cpp\r
                 )\r
 \r
+       ADD_EXECUTABLE(fcgi_hello\r
+  fcgi_helloworld.cpp\r
+                )\r
+\r
 ADD_EXECUTABLE(intrusive_ptr\r
   intrusive_ptr.cpp\r
 )\r
diff --git a/tests/fcgi_helloworld.cpp b/tests/fcgi_helloworld.cpp
new file mode 100644 (file)
index 0000000..78b0d53
--- /dev/null
@@ -0,0 +1,47 @@
+#if 0
+#include <windows.h>
+#include <winsock2.h>
+#endif
+
+#include <iostream>
+
+#include <aeb/net/ip/tcp.h>
+#include <aeb/net/ip/basic_endpoint.h>
+#include <aeb/net/socket_base.h>
+#include <aeb/net/io_dispatcher.h>
+#include <aeb/net/basic_socket_acceptor.h>
+#include <aeb/net/basic_socket_stream.h>
+#include <aeb/pointer/intrusive_ptr.h>
+#if defined(__MINGW32__) ||defined(_WIN32)
+#include <aeb/net/detail/winsock_init.h>
+#endif
+
+#include <aeb/fcgi/fcgi.h>
+#include <aeb/fcgi/fcgi_handler.h>
+
+using namespace aeb::net;
+typedef aeb::net::io_dispatcher<aeb::net::detail::socket_type,ip::tcp> io_service;
+typedef aeb::net::basic_socket<ip::tcp> tcp_socket;
+
+/**
+ * @brief main entry point. A simple example to use
+ * the fcgi implementation. Will use this test
+ * to verify the communication
+ *
+ *
+ */
+int main(int argc,char **argv)
+{
+
+  ip::basic_endpoint<ip::tcp> ep(ip::tcp::v4(),10224);
+
+  aeb::fcgi::acceptor a(ep);
+
+  a.listen();
+
+:  io_service *io = aeb::singleton<io_service>::get_instance();
+
+  io->register_handler(2,&a);
+
+  io->run(false);
+}