1 / 16

Serwer Http

Serwer Http. PROJEKT - Systemy OPERACYJNE 2012/13 Michał LISZCZ. Repozytorium. https://github.com/gitprofit/httpsrvr. Serwer WWW. Http Request. POST /index.html HTTP/1.1<br> Host: atasoyweb.net<br> User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1<br>

mika
Download Presentation

Serwer Http

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Serwer Http PROJEKT - Systemy OPERACYJNE 2012/13 Michał LISZCZ

  2. Repozytorium • https://github.com/gitprofit/httpsrvr

  3. Serwer WWW

  4. Http Request • POST /index.html HTTP/1.1\r\n • Host: atasoyweb.net\r\n • User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1\r\n • Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n • Accept-Language: tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3\r\n • Accept-Encoding: gzip, deflate\r\n • Connection: keep-alive\r\n • Referer: http://atasoyweb.net/\r\n • Content-Type: application/x-www-form-urlencoded\r\n • Content-Length: 35\r\n\r\n • variable1=value1&variable2=value2

  5. Http Response • HTTP/1.1 200 OK\r\n • Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)\r\n • Content-Length: {content_length}\r\n • Connection: close\r\n • Content-Type: text/html; charset=UTF-8\r\n\r\n • the content of which length is equal to {content_length}

  6. Implementacja • header-onlylibrary • OOP • opakowanie funkcji systemowych • plik konfiguracyjny • dużo std::shared_ptr • Eclipse

  7. Architektura

  8. server.config • wwwroot: /home/michal/Documents/HttpServer/wwwroot • Server-Name: Systemy Operacyjne 2013 • Listen-Port: 8080 • Default-Files: index.html index.htm

  9. ServerSocket classServerSocket { private: sockaddr_insockAddr; intsockFD; public: ServerSocket(int port); voidclose(); virtual ~ServerSocket(); std::shared_ptr<Socket> accept(); };

  10. Socket classSocket { friendclassServerSocket; private: intsockFD; Socket(intsockFD); public: voidclose(); virtual ~Socket(); std::shared_ptr<HttpRequest> read (std::shared_ptr<HttpRequestFactory> requestFactory); voidwrite (std::shared_ptr<HttpResponse> response); };

  11. SocketStreambuf classSocketStreambuf: publicstd::streambuf { friendclassSocketIstream; private: intstreamFD;charcurrChar;charnextChar;boolisEOS; SocketStreambuf(intunixFileDescriptor); char peek(); // discard all \r voidnext(); virtualint_typeunderflow(); virtualint_typeuflow(); virtualint_typepbackfail(int_type); virtualstd::streamsizeshowmanyc(); };

  12. SocketIstream classSocketIstream: publicstd::istream { private: SocketStreambufsb; public: SocketIstream(intunixFileDescriptor) : std::istream(&sb), sb(unixFileDescriptor) { } };

  13. Thread template<DetachStatedetachState, CancelTypecancelType> classThread { private: pthread_tthreadID = 0; staticvoid* threadStarter(void* callerThis) { // ... Thread* p = (Thread*) callerThis; p->run(); } staticvoidthreadCleanup(void* callerThis); public: pthread_tgetTID();virtualvoid run() = 0;Thread() = default;virtual~Thread() { } void start() { // ... pthread_create(&threadID, &attr, Thread::threadStarter, this); } voidcancel();voidjoin(); };

  14. Enum template <typenameDerviedEnum>classEnum{protected: conststd::string stringForm;Enum(conststd::string& stringForm) : stringForm(stringForm) { } public: conststd::string& toString() const { returnstringForm; } staticstd::shared_ptr<DerviedEnum> fromString(conststd::string& stringForm){ for(autov : DerviedEnum::values) // CRTPif(v->stringForm == stringForm)return v; throwException(...);} };

More Related