1/* 2 * Copyright 2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author(s): 6 * Ma Jie, china.majie at gmail 7 */ 8#ifndef POOR_MAN_SERVER_H 9#define POOR_MAN_SERVER_H 10 11#include <pthread.h> 12 13#include <OS.h> 14#include <SupportDefs.h> 15 16#include "libhttpd/libhttpd.h" 17 18#define POOR_MAN_BUF_SIZE 1048576ll 19 20#ifdef __cplusplus 21class PoorManServer{ 22public: 23 PoorManServer(const char* webDir, int32 maxConns, 24 bool listDir, const char* idxName); 25 virtual ~PoorManServer(); 26 27 status_t Run(); 28 status_t Stop(); 29 30 bool IsRunning()const{return fIsRunning;} 31 32 status_t SetWebDir(const char* webDir); 33 status_t SetMaxConns(int32 count); 34 status_t SetListDir(bool listDir); 35 status_t SetIndexName(const char* idxName); 36 37 pthread_rwlock_t* GetWebDirLock(){return &fWebDirLock;} 38 pthread_rwlock_t* GetIndexNameLock(){return &fIndexNameLock;} 39private: 40 bool fIsRunning; 41 int32 fMaxConns;//Max Thread Count 42 char* fIndexName;//Index File Name 43 44 thread_id fListenerTid; 45 int32 fCurConns; 46 httpd_server* fHttpdServer; 47 48 pthread_rwlock_t fWebDirLock; 49 pthread_rwlock_t fIndexNameLock; 50 51 PoorManServer(){} 52 PoorManServer(PoorManServer& s){} 53 PoorManServer& operator=(PoorManServer& s){return *this;} 54 55 //two thread functions. 56 static int32 _Listener(void* data); 57 static int32 _Worker(void* data); 58 59 status_t _HandleGet(httpd_conn* hc); 60 status_t _HandleHead(httpd_conn* hc); 61 status_t _HandlePost(httpd_conn* hc); 62}; 63#endif 64 65#ifdef __cplusplus 66extern "C" { 67#endif 68 69pthread_rwlock_t* get_web_dir_lock(); 70pthread_rwlock_t* get_index_name_lock(); 71 72#ifdef __cplusplus 73} 74#endif 75 76#endif //POOR_MAN_SERVER_H 77