-
Notifications
You must be signed in to change notification settings - Fork 65
/
SocketPlugin.c
2440 lines (2251 loc) · 64.7 KB
/
SocketPlugin.c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.2495 uuid: fcbf4c90-4c50-4ff3-8690-0edfded4f9c4
from
SocketPlugin VMMaker.oscog-eem.2495 uuid: fcbf4c90-4c50-4ff3-8690-0edfded4f9c4
*/
static char __buildInfo[] = "SocketPlugin VMMaker.oscog-eem.2495 uuid: fcbf4c90-4c50-4ff3-8690-0edfded4f9c4 " __DATE__ ;
#include "config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Default EXPORT macro that does nothing (see comment in sq.h): */
#define EXPORT(returnType) returnType
/* Do not include the entire sq.h file but just those parts needed. */
#include "sqConfig.h" /* Configuration options */
#include "sqVirtualMachine.h" /* The virtual machine proxy definition */
#include "sqPlatformSpecific.h" /* Platform specific definitions */
#define true 1
#define false 0
#define null 0 /* using 'null' because nil is predefined in Think C */
#ifdef SQUEAK_BUILTIN_PLUGIN
# undef EXPORT
# define EXPORT(returnType) static returnType
#endif
#include "SocketPlugin.h"
#include "sqMemoryAccess.h"
/*** Constants ***/
#define PrimErrBadArgument 3
/*** Function Prototypes ***/
EXPORT(const char*) getModuleName(void);
EXPORT(sqInt) initialiseModule(void);
static sqInt intToNetAddress(sqInt addr);
EXPORT(sqInt) moduleUnloaded(char *aModuleName);
static sqInt netAddressToInt(unsigned char *ptrToByteArray);
EXPORT(sqInt) primitiveInitializeNetwork(void);
EXPORT(sqInt) primitiveResolverAbortLookup(void);
EXPORT(sqInt) primitiveResolverAddressLookupResult(void);
EXPORT(sqInt) primitiveResolverError(void);
EXPORT(sqInt) primitiveResolverGetAddressInfo(void);
EXPORT(sqInt) primitiveResolverGetAddressInfoFamily(void);
EXPORT(sqInt) primitiveResolverGetAddressInfoNext(void);
EXPORT(sqInt) primitiveResolverGetAddressInfoProtocol(void);
EXPORT(sqInt) primitiveResolverGetAddressInfoResult(void);
EXPORT(sqInt) primitiveResolverGetAddressInfoSize(void);
EXPORT(sqInt) primitiveResolverGetAddressInfoType(void);
EXPORT(sqInt) primitiveResolverGetNameInfo(void);
EXPORT(sqInt) primitiveResolverGetNameInfoHostResult(void);
EXPORT(sqInt) primitiveResolverGetNameInfoHostSize(void);
EXPORT(sqInt) primitiveResolverGetNameInfoServiceResult(void);
EXPORT(sqInt) primitiveResolverGetNameInfoServiceSize(void);
EXPORT(sqInt) primitiveResolverHostNameResult(void);
EXPORT(sqInt) primitiveResolverHostNameSize(void);
EXPORT(sqInt) primitiveResolverLocalAddress(void);
EXPORT(sqInt) primitiveResolverNameLookupResult(void);
EXPORT(sqInt) primitiveResolverStartAddressLookup(void);
EXPORT(sqInt) primitiveResolverStartNameLookup(void);
EXPORT(sqInt) primitiveResolverStatus(void);
EXPORT(sqInt) primitiveSocketAbortConnection(void);
EXPORT(sqInt) primitiveSocketAccept(void);
EXPORT(sqInt) primitiveSocketAccept3Semaphores(void);
EXPORT(sqInt) primitiveSocketAddressGetPort(void);
EXPORT(sqInt) primitiveSocketAddressSetPort(void);
EXPORT(sqInt) primitiveSocketBindTo(void);
EXPORT(sqInt) primitiveSocketBindToPort(void);
EXPORT(sqInt) primitiveSocketCloseConnection(void);
EXPORT(sqInt) primitiveSocketConnectionStatus(void);
EXPORT(sqInt) primitiveSocketConnectTo(void);
EXPORT(sqInt) primitiveSocketConnectToPort(void);
EXPORT(sqInt) primitiveSocketCreate(void);
EXPORT(sqInt) primitiveSocketCreate3Semaphores(void);
EXPORT(sqInt) primitiveSocketCreateRAW(void);
EXPORT(sqInt) primitiveSocketDestroy(void);
EXPORT(sqInt) primitiveSocketError(void);
EXPORT(sqInt) primitiveSocketGetOptions(void);
EXPORT(sqInt) primitiveSocketListenOnPort(void);
EXPORT(sqInt) primitiveSocketListenOnPortBacklog(void);
EXPORT(sqInt) primitiveSocketListenOnPortBacklogInterface(void);
EXPORT(sqInt) primitiveSocketListenWithBacklog(void);
EXPORT(sqInt) primitiveSocketListenWithOrWithoutBacklog(void);
EXPORT(sqInt) primitiveSocketLocalAddress(void);
EXPORT(sqInt) primitiveSocketLocalAddressResult(void);
EXPORT(sqInt) primitiveSocketLocalAddressSize(void);
EXPORT(sqInt) primitiveSocketLocalPort(void);
EXPORT(sqInt) primitiveSocketReceiveDataAvailable(void);
EXPORT(sqInt) primitiveSocketReceiveDataBufCount(void);
EXPORT(sqInt) primitiveSocketReceiveUDPDataBufCount(void);
EXPORT(sqInt) primitiveSocketRemoteAddress(void);
EXPORT(sqInt) primitiveSocketRemoteAddressResult(void);
EXPORT(sqInt) primitiveSocketRemoteAddressSize(void);
EXPORT(sqInt) primitiveSocketRemotePort(void);
EXPORT(sqInt) primitiveSocketSendDataBufCount(void);
EXPORT(sqInt) primitiveSocketSendDone(void);
EXPORT(sqInt) primitiveSocketSendUDPDataBufCount(void);
EXPORT(sqInt) primitiveSocketSetOptions(void);
EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter);
EXPORT(sqInt) shutdownModule(void);
static sqInt socketRecordSize(void);
static SocketPtr socketValueOf(sqInt socketOop);
static sqInt sqAssert(sqInt aBool);
/*** Variables ***/
#if !defined(SQUEAK_BUILTIN_PLUGIN)
static sqInt (*byteSizeOf)(sqInt oop);
static sqInt (*classArray)(void);
static sqInt (*classByteArray)(void);
static sqInt (*classString)(void);
static sqInt (*failed)(void);
static sqInt (*falseObject)(void);
static void * (*firstIndexableField)(sqInt oop);
static sqInt (*instantiateClassindexableSize)(sqInt classPointer, sqInt size);
static sqInt (*integerObjectOf)(sqInt value);
static void * (*ioLoadFunctionFrom)(char *functionName, char *moduleName);
static sqInt (*isBytes)(sqInt oop);
static sqInt (*isIntegerObject)(sqInt objectPointer);
static sqInt (*isWords)(sqInt oop);
static sqInt (*isWordsOrBytes)(sqInt oop);
static sqInt (*methodArgumentCount)(void);
static sqInt (*pop)(sqInt nItems);
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
static sqInt (*popRemappableOop)(void);
static sqInt (*primitiveFail)(void);
static sqInt (*primitiveFailFor)(sqInt reasonCode);
static sqInt (*pushRemappableOop)(sqInt oop);
static sqInt (*slotSizeOf)(sqInt oop);
static sqInt (*stackIntegerValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
static sqInt (*storePointerofObjectwithValue)(sqInt index, sqInt oop, sqInt valuePointer);
static sqInt (*success)(sqInt aBoolean);
static sqInt (*trueObject)(void);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern sqInt byteSizeOf(sqInt oop);
extern sqInt classArray(void);
extern sqInt classByteArray(void);
extern sqInt classString(void);
extern sqInt failed(void);
extern sqInt falseObject(void);
extern void * firstIndexableField(sqInt oop);
extern sqInt instantiateClassindexableSize(sqInt classPointer, sqInt size);
extern sqInt integerObjectOf(sqInt value);
extern void * ioLoadFunctionFrom(char *functionName, char *moduleName);
extern sqInt isBytes(sqInt oop);
#if !defined(isIntegerObject)
extern sqInt isIntegerObject(sqInt objectPointer);
#endif
extern sqInt isWords(sqInt oop);
extern sqInt isWordsOrBytes(sqInt oop);
extern sqInt methodArgumentCount(void);
extern sqInt pop(sqInt nItems);
extern sqInt popthenPush(sqInt nItems, sqInt oop);
extern sqInt popRemappableOop(void);
extern sqInt primitiveFail(void);
extern sqInt primitiveFailFor(sqInt reasonCode);
extern sqInt pushRemappableOop(sqInt oop);
extern sqInt slotSizeOf(sqInt oop);
extern sqInt stackIntegerValue(sqInt offset);
extern sqInt stackValue(sqInt offset);
extern sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePointer);
extern sqInt success(sqInt aBoolean);
extern sqInt trueObject(void);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName =
#ifdef SQUEAK_BUILTIN_PLUGIN
"SocketPlugin VMMaker.oscog-eem.2495 (i)"
#else
"SocketPlugin VMMaker.oscog-eem.2495 (e)"
#endif
;
/* Note: This is hardcoded so it can be run from Squeak.
The module name is used for validating a module *after*
it is loaded to check if it does really contain the module
we're thinking it contains. This is important! */
/* InterpreterPlugin>>#getModuleName */
EXPORT(const char*)
getModuleName(void)
{
return moduleName;
}
/* SocketPlugin>>#initialiseModule */
EXPORT(sqInt)
initialiseModule(void)
{
return socketInit();
}
/* Convert the given 32-bit integer into an internet network address
represented as a four-byte ByteArray.
*/
/* SocketPlugin>>#intToNetAddress: */
static sqInt
intToNetAddress(sqInt addr)
{
char *naPtr;
sqInt netAddressOop;
netAddressOop = instantiateClassindexableSize(classByteArray(), 4);
naPtr = ((char *)firstIndexableField(netAddressOop));
naPtr[0] = (((char) ((((usqInt) addr) >> 24) & 0xFF)));
naPtr[1] = (((char) ((((usqInt) addr) >> 16) & 0xFF)));
naPtr[2] = (((char) ((((usqInt) addr) >> 8) & 0xFF)));
naPtr[3] = (((char) (addr & 0xFF)));
return netAddressOop;
}
/* The module with the given name was just unloaded.
Make sure we have no dangling references. */
/* SocketPlugin>>#moduleUnloaded: */
EXPORT(sqInt)
moduleUnloaded(char *aModuleName)
{
return 0;
}
/* Convert the given internet network address (represented as a four-byte
ByteArray) into a 32-bit integer. Fail if the given ptrToByteArray does
not appear to point to a four-byte ByteArray.
*/
/* SocketPlugin>>#netAddressToInt: */
static sqInt
netAddressToInt(unsigned char *ptrToByteArray)
{
sqInt sz;
sz = byteSizeOf(((sqInt)(sqIntptr_t)(ptrToByteArray) - BaseHeaderSize));
if (!(sz == 4)) {
return primitiveFail();
}
return (((ptrToByteArray[3]) + (((usqInt)((ptrToByteArray[2])) << 8))) + (((usqInt)((ptrToByteArray[1])) << 16))) + (((usqInt)((ptrToByteArray[0])) << 24));
}
/* SocketPlugin>>#primitiveInitializeNetwork: */
EXPORT(sqInt)
primitiveInitializeNetwork(void)
{
sqInt err;
sqInt resolverSemaIndex;
if (!(isIntegerObject(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
resolverSemaIndex = stackIntegerValue(0);
if (failed()) {
return null;
}
err = sqNetworkInit(resolverSemaIndex);
success(err == 0);
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverAbortLookup */
EXPORT(sqInt)
primitiveResolverAbortLookup(void)
{
sqResolverAbort();
return null;
}
/* SocketPlugin>>#primitiveResolverAddressLookupResult */
EXPORT(sqInt)
primitiveResolverAddressLookupResult(void)
{
sqInt s;
sqInt sz;
s = 0;
sz = sqResolverAddrLookupResultSize();
if (!(failed())) {
s = instantiateClassindexableSize(classString(), sz);
sqResolverAddrLookupResult(((char *)firstIndexableField(s)), sz);
}
if (!(failed())) {
popthenPush(1, s);
}
return null;
}
/* SocketPlugin>>#primitiveResolverError */
EXPORT(sqInt)
primitiveResolverError(void)
{
popthenPush(1, integerObjectOf((sqResolverError())));
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoHost:service:flags:family:type:protocol: */
EXPORT(sqInt)
primitiveResolverGetAddressInfo(void)
{
sqInt family;
sqInt flags;
char *hostName;
sqInt hostSize;
sqInt protocol;
char *servName;
sqInt servSize;
sqInt type;
if (!((isBytes(stackValue(5)))
&& ((isBytes(stackValue(4)))
&& ((isIntegerObject(stackValue(3)))
&& ((isIntegerObject(stackValue(2)))
&& ((isIntegerObject(stackValue(1)))
&& (isIntegerObject(stackValue(0))))))))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
hostName = ((char *) (firstIndexableField(stackValue(5))));
servName = ((char *) (firstIndexableField(stackValue(4))));
flags = stackIntegerValue(3);
family = stackIntegerValue(2);
type = stackIntegerValue(1);
protocol = stackIntegerValue(0);
if (failed()) {
return null;
}
if (!(failed())) {
hostSize = byteSizeOf(((sqInt)(sqIntptr_t)(hostName) - BaseHeaderSize));
servSize = byteSizeOf(((sqInt)(sqIntptr_t)(servName) - BaseHeaderSize));
sqResolverGetAddressInfoHostSizeServiceSizeFlagsFamilyTypeProtocol(hostName, hostSize, servName, servSize, flags, family, type, protocol);
}
if (!(failed())) {
pop(6);
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoFamily */
EXPORT(sqInt)
primitiveResolverGetAddressInfoFamily(void)
{
sqInt family;
if (!(failed())) {
family = sqResolverGetAddressInfoFamily();
if (!(failed())) {
popthenPush(1, integerObjectOf(family));
}
return null;
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoNext */
EXPORT(sqInt)
primitiveResolverGetAddressInfoNext(void)
{
sqInt more;
more = sqResolverGetAddressInfoNext();
if (failed()) {
return null;
}
if (!(failed())) {
popthenPush(1, ((more) ? trueObject() : falseObject()));
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoProtocol */
EXPORT(sqInt)
primitiveResolverGetAddressInfoProtocol(void)
{
sqInt protocol;
if (!(failed())) {
protocol = sqResolverGetAddressInfoProtocol();
if (!(failed())) {
popthenPush(1, integerObjectOf(protocol));
}
return null;
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoResult: */
EXPORT(sqInt)
primitiveResolverGetAddressInfoResult(void)
{
sqInt addrSize;
char *socketAddress;
if (!(isBytes(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
socketAddress = ((char *) (firstIndexableField(stackValue(0))));
if (failed()) {
return null;
}
if (!(failed())) {
addrSize = byteSizeOf(((sqInt)(sqIntptr_t)(socketAddress) - BaseHeaderSize));
sqResolverGetAddressInfoResultSize(socketAddress, addrSize);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoSize */
EXPORT(sqInt)
primitiveResolverGetAddressInfoSize(void)
{
sqInt size;
if (!(failed())) {
size = sqResolverGetAddressInfoSize();
if (!(failed())) {
popthenPush(1, integerObjectOf(size));
}
return null;
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetAddressInfoType */
EXPORT(sqInt)
primitiveResolverGetAddressInfoType(void)
{
sqInt type;
if (!(failed())) {
type = sqResolverGetAddressInfoType();
if (!(failed())) {
popthenPush(1, integerObjectOf(type));
}
return null;
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetNameInfo:flags: */
EXPORT(sqInt)
primitiveResolverGetNameInfo(void)
{
char *addrBase;
sqInt addrSize;
sqInt flags;
sqInt socketAddress;
if (!(isIntegerObject(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
socketAddress = stackValue(1);
flags = stackIntegerValue(0);
if (failed()) {
return null;
}
if (!(failed())) {
addrSize = byteSizeOf(socketAddress);
addrBase = ((char *) (firstIndexableField(socketAddress)));
sqResolverGetNameInfoSizeFlags(addrBase, addrSize, flags);
}
if (!(failed())) {
pop(2);
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetNameInfoHostResult: */
EXPORT(sqInt)
primitiveResolverGetNameInfoHostResult(void)
{
sqInt addrSize;
char *socketName;
if (!(isBytes(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
socketName = ((char *) (firstIndexableField(stackValue(0))));
if (failed()) {
return null;
}
if (!(failed())) {
addrSize = byteSizeOf(((sqInt)(sqIntptr_t)(socketName) - BaseHeaderSize));
sqResolverGetNameInfoHostResultSize(socketName, addrSize);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetNameInfoHostSize */
EXPORT(sqInt)
primitiveResolverGetNameInfoHostSize(void)
{
sqInt size;
if (!(failed())) {
size = sqResolverGetNameInfoHostSize();
if (!(failed())) {
popthenPush(1, integerObjectOf(size));
}
return null;
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetNameInfoServiceResult: */
EXPORT(sqInt)
primitiveResolverGetNameInfoServiceResult(void)
{
sqInt addrSize;
char *socketName;
if (!(isBytes(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
socketName = ((char *) (firstIndexableField(stackValue(0))));
if (failed()) {
return null;
}
if (!(failed())) {
addrSize = byteSizeOf(((sqInt)(sqIntptr_t)(socketName) - BaseHeaderSize));
sqResolverGetNameInfoServiceResultSize(socketName, addrSize);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverGetNameInfoServiceSize */
EXPORT(sqInt)
primitiveResolverGetNameInfoServiceSize(void)
{
sqInt size;
if (!(failed())) {
size = sqResolverGetNameInfoServiceSize();
if (!(failed())) {
popthenPush(1, integerObjectOf(size));
}
return null;
}
return null;
}
/* SocketPlugin>>#primitiveResolverHostNameResult: */
EXPORT(sqInt)
primitiveResolverHostNameResult(void)
{
sqInt nameSize;
char *nameString;
if (!(isBytes(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
nameString = ((char *) (firstIndexableField(stackValue(0))));
if (failed()) {
return null;
}
if (!(failed())) {
nameSize = byteSizeOf(((sqInt)(sqIntptr_t)(nameString) - BaseHeaderSize));
sqResolverHostNameResultSize(nameString, nameSize);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverHostNameSize */
EXPORT(sqInt)
primitiveResolverHostNameSize(void)
{
sqInt size;
if (!(failed())) {
size = sqResolverHostNameSize();
if (!(failed())) {
popthenPush(1, integerObjectOf(size));
return null;
}
}
return null;
}
/* SocketPlugin>>#primitiveResolverLocalAddress */
EXPORT(sqInt)
primitiveResolverLocalAddress(void)
{
sqInt addr;
sqInt _return_value;
addr = sqResolverLocalAddress();
if (!(failed())) {
_return_value = intToNetAddress(addr);
if (!(failed())) {
popthenPush(1, _return_value);
}
}
return null;
}
/* SocketPlugin>>#primitiveResolverNameLookupResult */
EXPORT(sqInt)
primitiveResolverNameLookupResult(void)
{
sqInt addr;
sqInt _return_value;
addr = sqResolverNameLookupResult();
if (!(failed())) {
_return_value = intToNetAddress(addr);
if (!(failed())) {
popthenPush(1, _return_value);
}
}
return null;
}
/* SocketPlugin>>#primitiveResolverStartAddressLookup: */
EXPORT(sqInt)
primitiveResolverStartAddressLookup(void)
{
sqInt addr;
char *address;
sqInt sz;
if (!(isBytes(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
address = ((char *) (firstIndexableField(stackValue(0))));
if (failed()) {
return null;
}
/* begin netAddressToInt: */
sz = byteSizeOf(((sqInt)(sqIntptr_t)((((unsigned char *) address))) - BaseHeaderSize));
if (!(sz == 4)) {
addr = primitiveFail();
goto l1;
}
addr = ((((((unsigned char *) address))[3]) + (((usqInt)(((((unsigned char *) address))[2])) << 8))) + (((usqInt)(((((unsigned char *) address))[1])) << 16))) + (((usqInt)(((((unsigned char *) address))[0])) << 24));
l1: /* end netAddressToInt: */;
if (!(failed())) {
sqResolverStartAddrLookup(addr);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverStartNameLookup: */
EXPORT(sqInt)
primitiveResolverStartNameLookup(void)
{
char *name;
sqInt sz;
if (!(isBytes(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
name = ((char *) (firstIndexableField(stackValue(0))));
if (failed()) {
return null;
}
if (!(failed())) {
sz = byteSizeOf(((sqInt)(sqIntptr_t)(name) - BaseHeaderSize));
sqResolverStartNameLookup(name, sz);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveResolverStatus */
EXPORT(sqInt)
primitiveResolverStatus(void)
{
sqInt status;
status = sqResolverStatus();
if (!(failed())) {
popthenPush(1, integerObjectOf(status));
}
return null;
}
/* SocketPlugin>>#primitiveSocketAbortConnection: */
EXPORT(sqInt)
primitiveSocketAbortConnection(void)
{
SocketPtr s;
sqInt socket;
socket = stackValue(0);
if (failed()) {
return null;
}
/* begin socketValueOf: */
if ((isBytes(socket))
&& ((byteSizeOf(socket)) == (sizeof(SQSocket)))) {
s = ((SocketPtr) (firstIndexableField(socket)));
}
else {
primitiveFailFor(PrimErrBadArgument);
s = null;
}
if (!(failed())) {
sqSocketAbortConnection(s);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveSocketAcceptFrom:rcvBufferSize:sndBufSize:semaIndex: */
EXPORT(sqInt)
primitiveSocketAccept(void)
{
sqInt recvBufSize;
SocketPtr s;
sqInt semaIndex;
sqInt sendBufSize;
SocketPtr serverSocket;
sqInt socketOop;
sqInt sockHandle;
socketOop = 0;
if (!((isIntegerObject(stackValue(2)))
&& ((isIntegerObject(stackValue(1)))
&& (isIntegerObject(stackValue(0)))))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
sockHandle = stackValue(3);
recvBufSize = stackIntegerValue(2);
sendBufSize = stackIntegerValue(1);
semaIndex = stackIntegerValue(0);
if (failed()) {
return null;
}
/* begin socketValueOf: */
if ((isBytes(sockHandle))
&& ((byteSizeOf(sockHandle)) == (sizeof(SQSocket)))) {
serverSocket = ((SocketPtr) (firstIndexableField(sockHandle)));
}
else {
primitiveFailFor(PrimErrBadArgument);
serverSocket = null;
}
if (!(failed())) {
socketOop = instantiateClassindexableSize(classByteArray(), sizeof(SQSocket));
/* begin socketValueOf: */
if ((isBytes(socketOop))
&& ((byteSizeOf(socketOop)) == (sizeof(SQSocket)))) {
s = ((SocketPtr) (firstIndexableField(socketOop)));
}
else {
primitiveFailFor(PrimErrBadArgument);
s = null;
}
sqSocketAcceptFromRecvBytesSendBytesSemaID(s, serverSocket, recvBufSize, sendBufSize, semaIndex);
}
if (!(failed())) {
popthenPush(5, socketOop);
}
return null;
}
/* SocketPlugin>>#primitiveSocketAcceptFrom:rcvBufferSize:sndBufSize:semaIndex:readSemaIndex:writeSemaIndex: */
EXPORT(sqInt)
primitiveSocketAccept3Semaphores(void)
{
sqInt aReadSema;
sqInt aWriteSema;
sqInt recvBufSize;
SocketPtr s;
sqInt semaIndex;
sqInt sendBufSize;
SocketPtr serverSocket;
sqInt socketOop;
sqInt sockHandle;
socketOop = 0;
if (!((isIntegerObject(stackValue(4)))
&& ((isIntegerObject(stackValue(3)))
&& ((isIntegerObject(stackValue(2)))
&& ((isIntegerObject(stackValue(1)))
&& (isIntegerObject(stackValue(0)))))))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
sockHandle = stackValue(5);
recvBufSize = stackIntegerValue(4);
sendBufSize = stackIntegerValue(3);
semaIndex = stackIntegerValue(2);
aReadSema = stackIntegerValue(1);
aWriteSema = stackIntegerValue(0);
if (failed()) {
return null;
}
/* begin socketValueOf: */
if ((isBytes(sockHandle))
&& ((byteSizeOf(sockHandle)) == (sizeof(SQSocket)))) {
serverSocket = ((SocketPtr) (firstIndexableField(sockHandle)));
}
else {
primitiveFailFor(PrimErrBadArgument);
serverSocket = null;
}
if (!(failed())) {
socketOop = instantiateClassindexableSize(classByteArray(), sizeof(SQSocket));
/* begin socketValueOf: */
if ((isBytes(socketOop))
&& ((byteSizeOf(socketOop)) == (sizeof(SQSocket)))) {
s = ((SocketPtr) (firstIndexableField(socketOop)));
}
else {
primitiveFailFor(PrimErrBadArgument);
s = null;
}
sqSocketAcceptFromRecvBytesSendBytesSemaIDReadSemaIDWriteSemaID(s, serverSocket, recvBufSize, sendBufSize, semaIndex, aReadSema, aWriteSema);
}
if (!(failed())) {
popthenPush(7, socketOop);
}
return null;
}
/* SocketPlugin>>#primitiveSocketAddressGetPort */
EXPORT(sqInt)
primitiveSocketAddressGetPort(void)
{
sqInt addr;
char *addrBase;
sqInt addrSize;
sqInt port;
addr = stackValue(0);
if (failed()) {
return null;
}
addrSize = byteSizeOf(addr);
addrBase = ((char *) (firstIndexableField(addr)));
if (!(failed())) {
port = sqSocketAddressSizeGetPort(addrBase, addrSize);
if (!(failed())) {
popthenPush(1, integerObjectOf(port));
return null;
}
}
return null;
}
/* SocketPlugin>>#primitiveSocketAddressSetPort: */
EXPORT(sqInt)
primitiveSocketAddressSetPort(void)
{
sqInt addr;
char *addrBase;
sqInt addrSize;
sqInt portNumber;
if (!(isIntegerObject(stackValue(0)))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
portNumber = stackIntegerValue(0);
addr = stackValue(1);
if (failed()) {
return null;
}
addrSize = byteSizeOf(addr);
addrBase = ((char *) (firstIndexableField(addr)));
if (!(failed())) {
sqSocketAddressSizeSetPort(addrBase, addrSize, portNumber);
}
if (!(failed())) {
pop(1);
}
return null;
}
/* SocketPlugin>>#primitiveSocket:bindTo: */
EXPORT(sqInt)
primitiveSocketBindTo(void)
{
char *addrBase;
sqInt addrSize;
SocketPtr s;
sqInt socket;
sqInt socketAddress;
socket = stackValue(1);
socketAddress = stackValue(0);
if (failed()) {
return null;
}
/* begin socketValueOf: */
if ((isBytes(socket))
&& ((byteSizeOf(socket)) == (sizeof(SQSocket)))) {
s = ((SocketPtr) (firstIndexableField(socket)));
}
else {
primitiveFailFor(PrimErrBadArgument);
s = null;
}
addrSize = byteSizeOf(socketAddress);
addrBase = ((char *) (firstIndexableField(socketAddress)));
if (!(failed())) {
sqSocketBindToAddressSize(s, addrBase, addrSize);
}
if (!(failed())) {
pop(2);
}
return null;
}
/* SocketPlugin>>#primitiveSocket:bindTo:port: */
EXPORT(sqInt)
primitiveSocketBindToPort(void)
{
sqInt addr;
char *address;
sqInt port;
SocketPtr s;
sqInt socket;
sqInt sz;
if (!((isBytes(stackValue(1)))
&& (isIntegerObject(stackValue(0))))) {
primitiveFailFor(PrimErrBadArgument);
return null;
}
socket = stackValue(2);
address = ((char *) (firstIndexableField(stackValue(1))));
port = stackIntegerValue(0);
if (failed()) {
return null;
}
/* begin netAddressToInt: */
sz = byteSizeOf(((sqInt)(sqIntptr_t)((((unsigned char *) address))) - BaseHeaderSize));
if (!(sz == 4)) {
addr = primitiveFail();
goto l1;
}
addr = ((((((unsigned char *) address))[3]) + (((usqInt)(((((unsigned char *) address))[2])) << 8))) + (((usqInt)(((((unsigned char *) address))[1])) << 16))) + (((usqInt)(((((unsigned char *) address))[0])) << 24));
l1: /* end netAddressToInt: */;
/* begin socketValueOf: */
if ((isBytes(socket))
&& ((byteSizeOf(socket)) == (sizeof(SQSocket)))) {
s = ((SocketPtr) (firstIndexableField(socket)));
}
else {
primitiveFailFor(PrimErrBadArgument);
s = null;
}
if (!(failed())) {
sqSocketBindToPort(s, addr, port);
}
if (!(failed())) {
pop(3);
}
return null;
}
/* SocketPlugin>>#primitiveSocketCloseConnection: */
EXPORT(sqInt)