source: cheroxy/trunk/src/main.cpp@ 20

Last change on this file since 20 was 20, checked in by cheese, 11 years ago

#1 fix and arrange exception handling

File size: 1.8 KB
Line 
1// LocalProxy.cpp : ÄÜ¼Ö ÀÀ¿ë ÇÁ·Î±×·¥¿¡ ´ëÇÑ ÁøÀÔÁ¡À» Á¤ÀÇÇÕ´Ï´Ù.
2//
3
4#ifdef _WIN32
5# define _CRT_SECURE_NO_WARNINGS
6#endif
7
8#include "CRXSocket.h"
9#include "CRXProxy.h"
10
11#include <iostream>
12#include <iomanip>
13#include <sstream>
14
15#include <stdio.h>
16#include <string.h>
17
18using namespace std;
19
20#ifdef _WIN32
21# define __func__ __FUNCTION__
22#endif
23
24#define CRX_PRINT_ERROR(__code, __message) \
25 do { \
26 char __error[4096] = {0x00, }; \
27 ostringstream __stream; \
28 __stream << __message; \
29 string __string = __stream.str (); \
30 sprintf (__error, "[%s][%d] (%d) %s\n", __func__, __LINE__, __code, __string.c_str ()); \
31 cout << __error; \
32 } while (0)
33
34int main (int argc, char* argv[])
35{
36 int aResult = 0;
37 const unsigned short aPort = 8080;
38
39 CRXSocket aSocket;
40 CRXProxy * aProxy = NULL;
41
42 /*----------------------------------------------------------------*/
43 /*----------------------------------------------------------------
44 * Initialize
45 *----------------------------------------------------------------*/
46 aResult = aSocket.CreateServer (aPort);
47 if (aResult < 0)
48 {
49 CRX_PRINT_ERROR (aResult, "failed to create server");
50 return aResult;
51 }
52
53 for (;;)
54 {
55 aResult = aSocket.Accept ();
56 if (aResult < 0)
57 {
58 CRX_PRINT_ERROR (aResult, "failed to accept");
59 break;
60 }
61
62 if ((aProxy = CRXProxy::GetNewInstance (aResult)) == NULL)
63 {
64 aResult = -1;
65 break;
66 }
67
68 aResult = aProxy->ForwardMT ();
69 if (aResult < 0)
70 {
71 CRX_PRINT_ERROR (aResult, "failed to create thread");
72 break;
73 }
74 }
75
76 /*----------------------------------------------------------------*/
77 aSocket.Close ();
78
79 return aResult;
80}
Note: See TracBrowser for help on using the repository browser.