Example #1
0
int main(int argc, char *argv[])
{
    	int nListenSock = -1, nLocalSock = -1, nRemoteSock = -1;
	pid_t nChild;	    	
	if (argc != 2) 							/* 命令行参数:“proxy1 本地端口” */
	{
    		PrintLog(stdout, "proxy1 LOCALPORT\n");
    		return 1;
    	}
    	/* ---------------------------父进程------------------------------- */
    											/* ① 创建侦听套接字 */
    	ASSERT(CreateSock(&nListenSock, atoi(argv[1]), 8) == 0);	
    	PrintLog(stdout, "listen service: service is activated.");
    	InitServer();							/* ② 进程转后台运行 */
  	while (1)
   	{
     										/* ③ 等待并创建连接套接字 */
    		if (!VERIFY(AcceptSock(&nLocalSock, nListenSock) == 0)) 	
				continue;					/* ③ 继续等待 */
		VERIFY((nChild = fork()) >= 0);		/* ④ 创建子进程 */
		if (nChild == 0) break;				/* 子进程跳转到子进程代码 */
		close(nLocalSock);					/* ⑤ 父进程关闭连接套接字 */
	}
	/* ---------------------------子进程------------------------------- */
	close(nListenSock);						/* ⑦ 子进程关闭侦听套接字 */
								/* 解析HTTP报文头,并与目标服务器建立连接 */
	if (HttpConnect(nLocalSock, &nRemoteSock) == 0)
		SendReciveServer(nLocalSock, nRemoteSock);			/* 通信转发 */
    	if (nLocalSock >= 0) close(nLocalSock);  /* ⑨ 子进程关闭本地端套接字 */
    	if (nRemoteSock >= 0) close(nRemoteSock);/* ⑨ 子进程关闭目标端套接字 */
}
Example #2
0
int main(int argc, char *argv[])
{
    	int nLocalSock = 0, nRemoteSock = -1;
								/* 解析HTTP报文头,并与目标服务器建立连接 */
	if (HttpConnect(nLocalSock, &nRemoteSock) == 0)
		SendReciveServer(nLocalSock, nRemoteSock);			/* 通信转发 */
    	if (nRemoteSock >= 0) close(nRemoteSock);/* ⑨ 子进程关闭目标端套接字 */
}
BOOL CHttpDownload::DownloadThread( FileContainerIterator& it )
{
	PatchLog( "Attempt to connect(%s).", m_sServer );
	
	if( !HttpConnect() )
	{
		OnError( DOWNLOAD_ERROR_HTTP_CONNECT );
		return FALSE;
	}

	PatchLog( "Connected" );

#if __CURRENT_LANG == LANG_FRA
	SetStatusText( _S(IDS_STR_FRA_PATCHPROCESS) );
#else
	SetStatusText( "Patch in process..." );
#endif
	for( ; it != m_pPatchManager->m_files.end(); ++it )
	{
		SetTextFileNum( m_nRecvdFile+1, m_pPatchManager->m_files.size() );
		
		UINT nResult = DownloadFile( *it );
		if( nResult == DOWNLOAD_ERROR_OK )
		{
			PatchLog( "%s OK", (*it).szServerPath );
			++m_nRecvdFile;
		}
		else
		{
			OnError( nResult );
			return FALSE;
		}		
	}

#if __CURRENT_LANG == LANG_FRA
	SetStatusText( _S(IDS_STR_FRA_PATCHCOMP) );
#elif __CURRENT_LANG == LANG_POR
	SetStatusText( _S(IDS_STR_POR_PATCHCOMP) );
#else
	SetStatusText( "Patch completed." );
#endif
	return TRUE ;
}