Texture: got rid of the image resizing, since you can just pass null data to glTexIma...
[io/quag.git] / projects / symbian / SymbianSockets.cpp
blob4852553a11b9a09c90d3b74e49276458625b98bc
1 #include <e32base.h>
2 #include <f32file.h>
3 #include <in_sock.h>
5 extern "C"
7 #include "IoState.h"
8 #include "IoNIL.h"
9 #include "IoMessage.h"
10 #include "IoNumber.h"
13 #include "SymbianMain.h"
14 #include "SymbianSockets.h"
16 #define min(a,b) ((a) < (b) ? (a) : (b))
17 #define SOCKET_BUFFER_SIZE 2048
19 class InternalSocket
21 public:
22 RSocket socket;
23 char buffer[SOCKET_BUFFER_SIZE];
24 int bufferTop;
25 int bufferBottom;
27 InternalSocket() :
28 bufferTop(0),
29 bufferBottom(0)
31 memset(buffer, 0, sizeof(buffer));
34 void ResetBuffer()
36 bufferTop = 0;
37 bufferBottom = 0;
38 memset(buffer, 0, sizeof(buffer));
41 TInt ReadIntoBuffer()
43 TRequestStatus status;
44 TPtr8 ptr8((TUint8*)buffer, sizeof(buffer), sizeof(buffer));
45 TSockXfrLength tlen;
46 socket.RecvOneOrMore(ptr8, 0, status, tlen);
47 User::WaitForRequest(status);
48 bufferTop = tlen();
49 bufferBottom = 0;
50 return status.Int();
53 TInt ReadChar(char* ch)
55 TInt status = KErrNone;
56 if(bufferTop == bufferBottom)
58 status = ReadIntoBuffer();
61 if(status == KErrNone)
63 *ch = buffer[bufferBottom++];
66 return status;
69 TInt ReadAllChars(char* ch, int length)
71 TInt status = KErrNone;
73 while(length > 0)
75 if(bufferTop == bufferBottom)
77 status = ReadIntoBuffer();
78 if(status != KErrNone)
79 break;
82 if(bufferTop - bufferBottom >= length)
84 memcpy(ch, buffer + bufferBottom, length);
85 bufferBottom += length;
86 length = 0;
88 else
90 int l = min(length, bufferTop - bufferBottom);
91 memcpy(ch, buffer + bufferBottom, l);
92 length -= l;
93 ch += l;
94 bufferBottom += l;
98 return status;
101 TInt ReadLine(char* ch, int length)
103 TInt status = KErrNone;
104 int state = 0;
106 while(length > 0)
108 if(bufferTop == bufferBottom)
110 status = ReadIntoBuffer();
111 if(status != KErrNone)
112 break;
115 if(bufferTop - bufferBottom >= length)
117 char* start = buffer + bufferBottom;
118 char* end = buffer + length;
120 while(start != end)
122 char c = *start++;
123 if(c == 13)
125 state = 1;
127 else if(c == 10)
129 if(state == 1)
131 state = 2;
132 bufferBottom = start - buffer;
133 length = 0;
134 return status;
135 break;
137 else
139 *ch++ = c;
142 else
144 if(state == 1)
146 *ch++ = 13;
148 else
150 *ch++ = c;
152 state = 0;
155 bufferBottom += length;
156 length = 0;
158 else
160 int l = min(length, bufferTop - bufferBottom);
161 char* start = buffer + bufferBottom;
162 char* end = buffer + l;
163 while(state != 2 && start != end)
165 char c = *start++;
166 if(c == 13)
168 state = 1;
170 else if(c == 10)
172 if(state == 1)
174 state = 2;
175 bufferBottom = start - buffer;
176 length = 0;
177 return status;
178 break;
180 else
182 *ch++ = c;
185 else
187 if(state == 1)
189 *ch++ = 13;
191 else
193 *ch++ = c;
195 state = 0;
199 length -= l;
200 ch += l;
201 bufferBottom += l;
204 return status;
207 TInt ReadOneOrMore(char* ch, int length)
209 TInt status = KErrNone;
211 if(bufferTop == bufferBottom)
213 status = ReadIntoBuffer();
214 if(status != KErrNone)
215 return status;
218 if(bufferTop - bufferBottom >= length)
220 memcpy(ch, buffer + bufferBottom, length);
221 bufferBottom += length;
223 else
225 int l = min(length, bufferTop - bufferBottom);
226 memcpy(ch, buffer + bufferBottom, l);
227 bufferBottom += l;
230 return status;
235 class CConnectingSocket;
236 class CReadLineSocket;
238 struct IoSocket
240 unsigned char color;
241 IoValue *previous;
242 IoValue *next;
243 IoTag *tag;
244 InternalSocket* socket;
245 char* host;
246 int port;
247 bool isConnected;
248 char* lineRead;
250 CConnectingSocket *activeConnect;
251 CReadLineSocket* activeReadLine;
254 IoValue *IoSocket_clone(IoSocket *self, IoValue *locals, IoMessage *m);
255 void IoSocket_free(IoSocket *self);
256 char *IoSocket_name(IoSocket *self);
257 void IoSocket_mark(IoSocket *self);
258 IoValue *IoSocket_host(IoSocket *self, IoValue *locals, IoMessage *m);
259 IoValue *IoSocket_host_(IoSocket *self, IoValue *locals, IoMessage *m);
260 IoValue *IoSocket_port(IoSocket *self, IoValue *locals, IoMessage *m);
261 IoValue *IoSocket_port_(IoSocket *self, IoValue *locals, IoMessage *m);
262 IoValue *IoSocket_open(IoSocket *self, IoValue *locals, IoMessage *m);
263 IoValue *IoSocket_connect(IoSocket *self, IoValue *locals, IoMessage *m);
264 IoValue *IoSocket_asyncConnect(IoSocket *self, IoValue *locals, IoMessage *m);
265 IoValue *IoSocket_waitForConnect(IoSocket *self, IoValue *locals, IoMessage *m);
266 IoValue *IoSocket_isConnected(IoSocket *self, IoValue *locals, IoMessage *m);
267 IoValue *IoSocket_isConnected_(IoSocket *self, IoValue *locals, IoMessage *m);
268 IoValue *IoSocket_write(IoSocket *self, IoValue *locals, IoMessage *m);
269 IoValue *IoSocket_writeLine(IoSocket *self, IoValue *locals, IoMessage *m);
270 IoValue *IoSocket_read(IoSocket *self, IoValue *locals, IoMessage *m);
271 IoValue *IoSocket_readLine(IoSocket *self, IoValue *locals, IoMessage *m);
272 IoValue *IoSocket_close(IoSocket *self, IoValue *locals, IoMessage *m);
274 IoValue *IoSocket_isLineRead(IoSocket *self, IoValue *locals, IoMessage *m);
275 IoValue *IoSocket_asyncReadLine(IoSocket *self, IoValue *locals, IoMessage *m);
276 IoValue *IoSocket_waitForReadLine(IoSocket *self, IoValue *locals, IoMessage *m);
277 IoValue *IoSocket_getLineRead(IoSocket *self, IoValue *locals, IoMessage *m);
279 class CConnectingSocket : public CActive
281 private:
282 InternalSocket* socket;
283 IoSocket* ioSocket;
284 int state;
285 RHostResolver resolver;
286 TNameEntry entry;
289 public:
290 static CConnectingSocket* NewL(InternalSocket* s, IoSocket* ios)
292 CConnectingSocket* self = new (ELeave) CConnectingSocket(s, ios);
293 self->ConstructL();
294 return self;
297 CConnectingSocket(InternalSocket* s, IoSocket* ios) :
298 CActive(CActive::EPriorityStandard),
299 socket(s),
300 ioSocket(ios),
301 state(0)
305 ~CConnectingSocket()
307 Cancel();
310 void ConstructL()
312 CActiveScheduler::Add(this);
315 void StartConnectL()
317 IoState* state = (IoState*)ioSocket->tag->state;
318 CConsoleControl* control = (CConsoleControl*)IoState_userData(state);
319 TInt result = resolver.Open(control->socketServer, 2048, 17);
320 if(result != 0)
322 Cancel();
323 IoState_error_description_(state, "IoSocket.connect", "Could not open resolver: '%d'\n", result);
325 else
327 TPtr16 ptr16 = stringToPtr16(ioSocket->host);
328 resolver.GetByName(ptr16, entry, iStatus);
329 SetActive();
333 void RunL()
335 if(state == 0)
337 if(iStatus.Int() != 0)
339 Cancel();
340 IoState_error_description_((IoState*)ioSocket->tag->state, "IoSocket.connect", "resolver.GetByName: '%d'\n", iStatus.Int());
342 state = 1;
343 TNameRecord record(entry());
344 TSockAddr addr(record.iAddr);
345 addr.SetPort(ioSocket->port);
346 resolver.Close();
348 socket->socket.Connect(addr, iStatus);
349 SetActive();
351 else if(state == 1)
353 ioSocket->isConnected = 1;
354 if(iStatus.Int() != 0)
356 Cancel();
357 IoState_error_description_((IoState*)ioSocket->tag->state, "IoSocket.connect", "socket.connect: '%d'\n", iStatus.Int());
362 void DoCancel()
364 if(state == 0)
366 resolver.Close();
368 socket->socket.CancelAll();
369 socket->socket.Close();
373 #define READ_STATE_BUFFER_UNDERFLOW 1
374 #define READ_STATE_BUFFER_READ 2
375 #define READ_STATE_BUFFER_POST_UNDERFLOW 3
376 #define READ_STATE_BUFFER_COMPLETE 4
378 class CReadLineSocket : public CActive
380 private:
381 InternalSocket* socket;
382 IoSocket* ioSocket;
383 char* originalBuffer;
384 char* buffer;
385 int length;
386 int state;
387 int lineState;
388 TSockXfrLength tlen;
390 public:
391 static CReadLineSocket* NewL(InternalSocket* s, IoSocket* ios, char* buffer, int length)
393 CReadLineSocket* self = new (ELeave) CReadLineSocket(s, ios, buffer, length);
394 self->ConstructL();
395 return self;
398 CReadLineSocket(InternalSocket* s, IoSocket* ios, char* b, int len) :
399 CActive(CActive::EPriorityStandard),
400 socket(s),
401 ioSocket(ios),
402 state(0),
403 lineState(0),
404 buffer(b),
405 originalBuffer(b),
406 length(len)
410 ~CReadLineSocket()
412 Cancel();
415 void ConstructL()
417 CActiveScheduler::Add(this);
420 void CheckBuffer()
422 if(length <= 0)
424 state = READ_STATE_BUFFER_COMPLETE;
426 else if(socket->bufferTop == socket->bufferBottom)
428 state = READ_STATE_BUFFER_UNDERFLOW;
430 else
432 state = READ_STATE_BUFFER_READ;
434 TRequestStatus* tempStatus = &iStatus;
435 User::RequestComplete(tempStatus, KErrNone);
438 void StartReadLineL()
440 SetActive();
441 CheckBuffer();
444 void RunL()
446 switch(state)
448 case READ_STATE_BUFFER_UNDERFLOW:
450 TPtr8 ptr8((TUint8*)socket->buffer, SOCKET_BUFFER_SIZE, SOCKET_BUFFER_SIZE);
451 socket->socket.RecvOneOrMore(ptr8, 0, iStatus, tlen);
452 state = READ_STATE_BUFFER_POST_UNDERFLOW;
453 SetActive();
454 break;
457 case READ_STATE_BUFFER_POST_UNDERFLOW:
459 socket->bufferTop = tlen();
460 socket->bufferBottom = 0;
461 state = READ_STATE_BUFFER_READ;
462 SetActive();
463 TRequestStatus* tempStatus = &iStatus;
464 User::RequestComplete(tempStatus, KErrNone);
465 break;
468 case READ_STATE_BUFFER_READ:
470 if(length == 0)
472 state = READ_STATE_BUFFER_COMPLETE;
473 SetActive();
474 TRequestStatus* tempStatus = &iStatus;
475 User::RequestComplete(tempStatus, KErrNone);
476 break;
478 else if(socket->bufferTop == socket->bufferBottom)
480 state = READ_STATE_BUFFER_UNDERFLOW;
481 SetActive();
482 TRequestStatus* tempStatus = &iStatus;
483 User::RequestComplete(tempStatus, KErrNone);
484 break;
486 else if(socket->bufferTop - socket->bufferBottom >= length)
488 char* start = socket->buffer + socket->bufferBottom;
489 char* end = socket->buffer + length;
491 while(start != end)
493 char c = *start++;
494 if(c == 13)
496 lineState = 1;
498 else if(c == 10)
500 if(lineState == 1)
502 lineState = 2;
503 socket->bufferBottom = start - socket->buffer;
504 length = 0;
505 state = READ_STATE_BUFFER_COMPLETE;
506 SetActive();
507 TRequestStatus* tempStatus = &iStatus;
508 User::RequestComplete(tempStatus, KErrNone);
509 return;
511 else
513 *buffer++ = c;
516 else
518 if(lineState == 1)
520 *buffer++ = 13;
522 else
524 *buffer++ = c;
526 state = 0;
529 socket->bufferBottom += length;
530 length = 0;
531 state = READ_STATE_BUFFER_COMPLETE;
532 SetActive();
533 TRequestStatus* tempStatus = &iStatus;
534 User::RequestComplete(tempStatus, KErrNone);
535 return;
537 else
539 int l = min(length, socket->bufferTop - socket->bufferBottom);
540 char* start = socket->buffer + socket->bufferBottom;
541 char* end = socket->buffer + l;
542 while(lineState != 2 && start != end)
544 char c = *start++;
545 if(c == 13)
547 lineState = 1;
549 else if(c == 10)
551 if(lineState == 1)
553 lineState = 2;
554 socket->bufferBottom = start - socket->buffer;
555 state = READ_STATE_BUFFER_COMPLETE;
556 SetActive();
557 TRequestStatus* tempStatus = &iStatus;
558 User::RequestComplete(tempStatus, KErrNone);
559 return;
561 else
563 *buffer++ = c;
566 else
568 if(lineState == 1)
570 *buffer++ = 13;
572 else
574 *buffer++ = c;
576 lineState = 0;
580 length -= l;
581 buffer += l;
582 socket->bufferBottom += l;
585 state = READ_STATE_BUFFER_READ;
586 SetActive();
587 TRequestStatus* tempStatus = &iStatus;
588 User::RequestComplete(tempStatus, KErrNone);
589 break;
592 case READ_STATE_BUFFER_COMPLETE:
594 ioSocket->lineRead = originalBuffer;
595 break;
600 void DoCancel()
602 socket->socket.CancelAll();
607 IoTag *IoSocket_initTagWithId_(void *ioState, int tagId)
609 IoTag *tag = IoTag_new();
610 tag->state = ioState;
611 tag->freeCallback = (TagFreeCallback *)IoSocket_free;
612 tag->nameCallback = (TagNameCallback *)IoSocket_name;
613 tag->markCallback = (TagMarkCallback *)IoSocket_mark;
615 Tag_addMethod(tag, "clone", (void*)IoSocket_clone);
616 Tag_addMethod(tag, "setHost", (void*)IoSocket_host_);
617 Tag_addMethod(tag, "host", (void*)IoSocket_host);
618 Tag_addMethod(tag, "setPort", (void*)IoSocket_port_);
619 Tag_addMethod(tag, "port", (void*)IoSocket_port);
620 Tag_addMethod(tag, "open", (void*)IoSocket_open);
621 Tag_addMethod(tag, "connect", (void*)IoSocket_connect);
622 Tag_addMethod(tag, "asyncConnect", (void*)IoSocket_asyncConnect);
623 Tag_addMethod(tag, "waitForConnect", (void*)IoSocket_waitForConnect);
624 Tag_addMethod(tag, "isConnected", (void*)IoSocket_isConnected);
625 Tag_addMethod(tag, "setIsConnected", (void*)IoSocket_isConnected_);
626 Tag_addMethod(tag, "write", (void*)IoSocket_write);
627 Tag_addMethod(tag, "writeLine", (void*)IoSocket_writeLine);
628 Tag_addMethod(tag, "read", (void*)IoSocket_read);
629 Tag_addMethod(tag, "readLine", (void*)IoSocket_readLine);
630 Tag_addMethod(tag, "close", (void*)IoSocket_close);
633 Tag_addMethod(tag, "isLineRead", (void*)IoSocket_isLineRead);
634 Tag_addMethod(tag, "asyncReadLine", (void*)IoSocket_asyncReadLine);
635 Tag_addMethod(tag, "waitForReadLine", (void*)IoSocket_waitForReadLine);
636 Tag_addMethod(tag, "getLineRead", (void*)IoSocket_getLineRead);
638 return tag;
641 IoSocket *IoSocket_new(void *state)
643 IoTag *tag = IoState_tagWithInitFunction_((IoState*)state, IoSocket_initTagWithId_);
644 IoSocket *self = (IoSocket *)malloc(sizeof(IoSocket));
645 memset(self, 0x0, sizeof(IoSocket));
646 self->tag = tag;
647 self->color = IOVALUE_WHITE();
648 self->socket = new InternalSocket();
649 self->host = strdup("localhost");
650 self->isConnected = false;
651 self->lineRead = 0;
652 self->activeConnect = 0;
653 self->activeReadLine = 0;
654 IoState_addValue_((IoState*)self->tag->state, (IoValue *)self);
655 return self;
658 IoValue *IoSocket_clone(IoSocket *self, IoValue *locals, IoMessage *m)
660 IoSocket *newSocket = IoSocket_new(self->tag->state);
661 newSocket->host = strdup(self->host);
662 return (IoValue *)newSocket;
665 void IoSocket_free(IoSocket *self)
667 if(self->activeConnect)
669 delete self->activeConnect;
670 self->activeConnect = 0;
672 self->socket->socket.Close();
673 delete self->socket;
674 self->socket = 0;
675 free(self->host);
676 free(self);
679 char *IoSocket_name(IoSocket *self)
681 return "Socket";
684 void IoSocket_mark(IoSocket *self)
688 IoValue *IoSocket_host(IoSocket *self, IoValue *locals, IoMessage *m)
690 return (IoValue *)USTRING(self->host);
693 IoValue *IoSocket_host_(IoSocket *self, IoValue *locals, IoMessage *m)
695 IoString *host = (IoString*)IoMessage_locals_stringArgAt_(m, locals, 0);
696 self->host = strdup(CSTRING(host));
697 return (IoValue *)self;
700 IoValue *IoSocket_port(IoSocket *self, IoValue *locals, IoMessage *m)
702 return (IoValue *)IONUMBER(self->port);
705 IoValue *IoSocket_port_(IoSocket *self, IoValue *locals, IoMessage *m)
707 IoNumber *port = (IoNumber*)IoMessage_locals_numberArgAt_(m, locals, 0);
708 self->port = IoNumber_asInt(port);
709 return (IoValue *)self;
712 IoValue *IoSocket_isConnected(IoSocket *self, IoValue *locals, IoMessage *m)
714 return (IoValue *)IONUMBER(self->isConnected);
717 IoValue *IoSocket_isConnected_(IoSocket *self, IoValue *locals, IoMessage *m)
719 IoNumber *isConnected = (IoNumber*)IoMessage_locals_numberArgAt_(m, locals, 0);
720 self->isConnected = IoNumber_asInt(isConnected);
721 return (IoValue *)self;
724 IoValue *IoSocket_open(IoSocket *self, IoValue *locals, IoMessage *m)
726 self->socket->ResetBuffer();
727 IoState* state = (IoState*)self->tag->state;
728 CConsoleControl* control = (CConsoleControl*)IoState_userData(state);
730 return (IoValue *)IONUMBER(self->socket->socket.Open(control->socketServer, KAfInet, KSockStream, KProtocolInetTcp));
733 IoValue *IoSocket_connect(IoSocket *self, IoValue *locals, IoMessage *m)
735 if(self->activeConnect)
737 delete self->activeConnect;
739 self->activeConnect = CConnectingSocket::NewL(self->socket, self);
740 self->activeConnect->StartConnectL();
741 IoState* state = (IoState*)self->tag->state;
742 while(!self->isConnected)
744 IoState_yield(state);
746 return (IoValue*)self;
749 IoValue *IoSocket_asyncConnect(IoSocket *self, IoValue *locals, IoMessage *m)
751 if(self->activeConnect)
753 delete self->activeConnect;
755 self->activeConnect = CConnectingSocket::NewL(self->socket, self);
756 self->activeConnect->StartConnectL();
757 return (IoValue*)self;
760 IoValue *IoSocket_waitForConnect(IoSocket *self, IoValue *locals, IoMessage *m)
762 IoState* state = (IoState*)self->tag->state;
763 while(!self->isConnected)
765 IoState_yield(state);
767 return (IoValue*)self;
770 IoValue *IoSocket_asyncReadLine(IoSocket *self, IoValue *locals, IoMessage *m)
772 if(self->activeReadLine)
774 delete self->activeReadLine;
777 IoNumber *size = (IoNumber*)IoMessage_locals_numberArgAt_(m, locals, 0);
778 int trueSize = IoNumber_asInt(size);
779 char* buffer = (char*)malloc(trueSize + 1);
780 memset(buffer, 0, trueSize + 1);
781 self->activeReadLine = CReadLineSocket::NewL(self->socket, self, buffer, trueSize);
782 self->activeReadLine->StartReadLineL();
783 return (IoValue*)self;
786 IoValue *IoSocket_waitForReadLine(IoSocket *self, IoValue *locals, IoMessage *m)
788 IoState* state = (IoState*)self->tag->state;
789 while(!self->lineRead)
791 IoState_yield(state);
793 IoValue* value = (IoValue*)USTRING(self->lineRead);
794 free(self->lineRead);
795 self->lineRead = 0;
796 return (IoValue*)value;
799 IoValue *IoSocket_isLineRead(IoSocket *self, IoValue *locals, IoMessage *m)
801 bool value = self->lineRead != 0;
802 return (IoValue *)IONUMBER(value);
805 IoValue *IoSocket_getLineRead(IoSocket *self, IoValue *locals, IoMessage *m)
807 return (IoValue*)USTRING(self->lineRead);
810 IoValue *IoSocket_close(IoSocket *self, IoValue *locals, IoMessage *m)
812 if(self->activeConnect)
814 delete self->activeConnect;
815 self->activeConnect = 0;
817 if(self->activeReadLine)
819 delete self->activeReadLine;
820 self->activeReadLine = 0;
822 self->socket->socket.Close();
823 return (IoValue*)self;
826 IoValue *IoSocket_write(IoSocket *self, IoValue *locals, IoMessage *m)
828 IoState* state = (IoState*)self->tag->state;
829 IoString *ioText = (IoString*)IoMessage_locals_stringArgAt_(m, locals, 0);
830 char* text = CSTRING(ioText);
831 int len = strlen(text);
832 TRequestStatus status;
833 TPtr8 ptr8((TUint8*)text, len, len);
834 self->socket->socket.Write(ptr8, status);
835 User::WaitForRequest(status);
836 if(status.Int() != 0)
838 IoState_error_description_(state, "IoSocket.write", "RSocket.Write: '%d'\n", status.Int());
841 return (IoValue*)self;
844 IoValue *IoSocket_writeLine(IoSocket *self, IoValue *locals, IoMessage *m)
846 IoState* state = (IoState*)self->tag->state;
847 IoString *ioText = (IoString*)IoMessage_locals_stringArgAt_(m, locals, 0);
848 char* text = strdup(CSTRING(ioText));
849 int len = strlen(text);
850 text = (char*)realloc(text, len + 3);
851 text[len] = 13;
852 text[len + 1] = 10;
853 text[len + 2] = 0;
855 TRequestStatus status;
856 TPtr8 ptr8((TUint8*)text, len + 2, len + 3);
857 self->socket->socket.Write(ptr8, status);
858 free(text);
859 User::WaitForRequest(status);
860 if(status.Int() != 0)
862 IoState_error_description_(state, "IoSocket.write", "RSocket.Write: '%d'\n", status.Int());
865 return (IoValue*)self;
868 IoValue *IoSocket_read(IoSocket *self, IoValue *locals, IoMessage *m)
870 IoNumber *size = (IoNumber*)IoMessage_locals_numberArgAt_(m, locals, 0);
871 IoState* state = (IoState*)self->tag->state;
872 int trueSize = IoNumber_asInt(size);
873 char* buffer = (char*)malloc(trueSize + 1);
874 memset(buffer, 0, trueSize + 1);
875 TInt status = self->socket->ReadOneOrMore(buffer, trueSize);
876 if(status != 0)
878 IoState_error_description_(state, "IoSocket.read", "RSocket.Read: '%d'\n", status);
881 IoValue* result = (IoValue*)USTRING(buffer);
882 free(buffer);
883 return result;
886 IoValue *IoSocket_readLine(IoSocket *self, IoValue *locals, IoMessage *m)
888 IoNumber *size = (IoNumber*)IoMessage_locals_numberArgAt_(m, locals, 0);
889 IoState* state = (IoState*)self->tag->state;
890 if(self->activeReadLine)
892 delete self->activeReadLine;
893 self->activeReadLine = 0;
895 int trueSize = IoNumber_asInt(size);
896 char* buffer = (char*)malloc(trueSize + 1);
897 memset(buffer, 0, trueSize + 1);
898 self->activeReadLine = CReadLineSocket::NewL(self->socket, self, buffer, trueSize);
899 self->activeReadLine->StartReadLineL();
900 while(!self->lineRead)
902 IoState_yield(state);
904 IoValue* value = (IoValue*)USTRING(self->lineRead);
905 free(self->lineRead);
906 self->lineRead = 0;
907 return (IoValue*)value;
912 void initSocketAddons(IoState* state)
914 IoState_addTagWithInitFunc_(state, IoSocket_initTagWithId_);
915 IoObject_setSlot_to_(state->lobby, IoState_stringWithCString_(state, "Socket"), IoSocket_new(state));