72
86
FD_ZERO(&writefds);
73
87
FD_ZERO(&errorfds);
75
FD_SET(commsSocket, &readfds);
76
FD_SET(commsSocket, &errorfds);
77
maxSocket = MAX(maxSocket, commsSocket);
89
FD_SET(socket, &readfds);
90
FD_SET(socket, &errorfds);
91
maxSocket = MAX(maxSocket, socket);
92
if (FD_ISSET(commsSocket, &readfds))
106
if (FD_ISSET(socket, &readfds))
94
108
//NSLog(@"receiving...");
95
109
if (!expectedMessageSize)
98
112
int actuallyRead = 0;
100
actuallyRead = recv(commsSocket, &buf, sizeof(uint32_t), MSG_PEEK);
114
actuallyRead = recv(socket, &buf, sizeof(uint32_t), MSG_PEEK);
102
116
if (actuallyRead == sizeof(uint32_t))
104
actuallyRead = recv(commsSocket, &buf, sizeof(uint32_t), 0);
118
actuallyRead = recv(socket, &buf, sizeof(uint32_t), 0);
105
119
expectedMessageSize = ntohl(buf);
106
120
currentData = [[NSMutableData alloc] initWithLength: expectedMessageSize];
132
else if (actuallyRead == 0)
134
printf("remote socket closed.\n");
121
140
size_t readAmount = expectedMessageSize - currentlyRead;
122
141
int actuallyRead = 0;
124
actuallyRead = recv(commsSocket, [currentData mutableBytes] + currentlyRead, readAmount, 0);
143
actuallyRead = recv(socket, [currentData mutableBytes] + currentlyRead, readAmount, 0);
125
144
if (actuallyRead == -1)
128
self->commsSocket = 0;
129
146
printf("Connection dropped with error.\n");
149
else if (actuallyRead == 0)
151
printf("remote socket closed.\n");
132
155
currentlyRead += actuallyRead;
134
157
if (currentlyRead == expectedMessageSize)
224
247
size_t dataSent = 0;
225
248
uint32_t header = htonl([data length]);
254
socket = commsSocket;
228
257
while (dataSent < sizeToSend)
230
if ((err = send(commsSocket, &header + dataSent, sizeToSend - dataSent, 0)) == -1)
259
if ((err = send(socket, &header + dataSent, sizeToSend - dataSent, 0)) == -1)
243
272
while (dataSent < sizeToSend)
245
if ((err = send(commsSocket, [data bytes] + dataSent, sizeToSend - dataSent, 0)) == -1)
274
if ((err = send(socket, [data bytes] + dataSent, sizeToSend - dataSent, 0)) == -1)
320
@interface GSEventProxy : NSObject
325
unsigned int ignored1;
330
unsigned int ignored2[10];
331
unsigned int ignored3[7];
336
unsigned int ignored4[3];
339
@implementation GSEventProxy
342
@implementation UIEvent (Synthesize)
344
- (id)initWithTouches:(NSSet *) touches
346
UITouch* touch = [touches anyObject];
347
CGPoint location = [touch locationInView: touch.window];
348
GSEventProxy *gsEventProxy = [[GSEventProxy alloc] init];
349
gsEventProxy->x1 = location.x;
350
gsEventProxy->y1 = location.y;
351
gsEventProxy->x2 = location.x;
352
gsEventProxy->y2 = location.y;
353
gsEventProxy->x3 = location.x;
354
gsEventProxy->y3 = location.y;
355
gsEventProxy->sizeX = 1.0;
356
gsEventProxy->sizeY = 1.0;
357
gsEventProxy->flags = ([touch phase] == UITouchPhaseEnded) ? 0x1010180 : 0x3010180;
358
gsEventProxy->type = 3001;
361
// On SDK versions 3.0 and greater, we need to reallocate as a
364
Class touchesEventClass = objc_getClass("UITouchesEvent");
365
if (touchesEventClass && ![[self class] isEqual: touchesEventClass])
368
self = [touchesEventClass alloc];
371
self = [self _initWithEvent:gsEventProxy touches:touches];
378
351
void _printGSPathPoint(GSTouchPointRef p)
380
353
// printf("P: 0x%08X 0x%08X 0x%08X 0x%08X (%G, %G)\n", p->unk0, p->unk1, p->unk2, p->unk5, p->x, p->y);