-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMacWifiTest.cpp
More file actions
97 lines (79 loc) · 1.91 KB
/
Copy pathMacWifiTest.cpp
File metadata and controls
97 lines (79 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <string.h>
#include "MacWifiLib.h"
#include "Util.h"
#define arraylen(arr) ((int) (sizeof (arr) / sizeof (arr)[0]))
string _requests[4][2] =
{
{ "Small http request", "http://httpbin.org/status/418" },
{ "Small https request", "https://httpbin.org/status/418" },
{ "Facebook", "https://facebook.com" },
{ "Google", "https://google.com" }
};
bool _doRequest = true;
int _curRequest = 0;
MacWifiLib _wifiLib;
Util _util;
void DoRequest(const string& title, const string& url);
void OnResponse(MacWifiResponse& response);
pascal OSErr ProcessResponseEvent(AppleEvent* appleEvent, AppleEvent* reply, long refCon);
int main()
{
EventRecord event;
AEInstallEventHandler(
kCoreEventClass,
kAEAnswer,
(AEEventHandlerUPP)ProcessResponseEvent,
0L,
false);
while (_curRequest < arraylen(_requests))
{
if (_doRequest)
{
DoRequest(_requests[_curRequest][0], _requests[_curRequest][1]);
}
if (WaitNextEvent(everyEvent, &event, 0, NULL))
{
switch (event.what)
{
case kHighLevelEvent:
AEProcessAppleEvent(&event);
break;
}
}
}
printf("All done!\n");
getchar(); getchar();
return 0;
}
void DoRequest(const string& title, const string& url)
{
printf("%s (press return)...\n", title.c_str());
fflush(stdout);
getchar(); getchar();
printf("%s says:\n\n", url.c_str());
_util.StartTimer();
_wifiLib.Get(url, OnResponse);
_doRequest = false;
}
void OnResponse(MacWifiResponse& response)
{
int timeTaken = _util.StopTimer();
printf("\n\nRequest took %dms.\n\n", timeTaken);
printf("Status: %d\n\n", response.StatusCode);
if (response.Success)
{
printf("\n\nContent:\n\n");
printf("%s\n\n", response.Content.c_str());
}
else
{
printf("ERROR: %s\n\n", response.ErrorMsg.c_str());
}
_curRequest++;
_doRequest = true;
}
pascal OSErr ProcessResponseEvent(AppleEvent* appleEvent, AppleEvent* reply, long refCon)
{
_wifiLib.ProcessReply(appleEvent);
}