00001 /* 00002 Free Download Manager Copyright (c) 2003-2007 FreeDownloadManager.ORG 00003 Open Download Manager Copyright (c) 2008 OpenDownloadManager.ORG 00004 */ 00005 00006 #include "stdafx.h" 00007 #include "vmsHttpConnection.h" 00008 #include "vmsHttpResponse.h" 00009 #include "vmsHttpResourceContainer.h" 00010 #include "vmsHttpServer.h" 00011 00012 vmsHttpConnection::vmsHttpConnection(vmsHttpServer* pServer) 00013 { 00014 m_pServer = pServer; 00015 m_sConnection = INVALID_SOCKET; 00016 } 00017 00018 vmsHttpConnection::~vmsHttpConnection() 00019 { 00020 Shutdown (); 00021 } 00022 00023 void vmsHttpConnection::Attach(SOCKET sConnection) 00024 { 00025 m_sConnection = sConnection; 00026 00027 DWORD dw; 00028 CloseHandle ( 00029 CreateThread (NULL, 0, _threadConnection, this, 0, &dw)); 00030 } 00031 00032 DWORD WINAPI vmsHttpConnection::_threadConnection(LPVOID lp) 00033 { 00034 vmsHttpConnection *pthis = (vmsHttpConnection*) lp; 00035 00036 if (FALSE == pthis->m_request.Receive (pthis->m_sConnection)) 00037 { 00038 pthis->Shutdown (); 00039 return 1; 00040 } 00041 00042 vmsHttpResponse response; 00043 00044 response.set_HttpVersion ("HTTP/1.1"); 00045 response.set_ResponseCode ("200 OK"); 00046 response.set_Body (NULL, 0); 00047 00048 pthis->m_pServer->get_ResourceContainer ()->ProcessRequest (pthis->m_request, 00049 response); 00050 00051 if (FALSE == response.Send (pthis->m_sConnection)) 00052 { 00053 pthis->Shutdown (); 00054 return 1; 00055 } 00056 00057 pthis->Shutdown (); 00058 return 0; 00059 } 00060 00061 void vmsHttpConnection::Shutdown() 00062 { 00063 if (m_sConnection != INVALID_SOCKET) 00064 { 00065 shutdown (m_sConnection, 2); 00066 closesocket (m_sConnection); 00067 m_sConnection = INVALID_SOCKET; 00068 } 00069 }
1.5.6