2 #include "structdefs.h"
3 #include <sys/socket.h>
8 #include "SimpleHash.h"
9 #include "GenericHashtable.h"
11 extern struct RuntimeHash *fdtoobject;
13 int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSocket___ * ___this___, int port) {
17 struct sockaddr_in sin;
19 bzero (&sin, sizeof (sin));
20 sin.sin_family = AF_INET;
21 sin.sin_port = htons (port);
22 sin.sin_addr.s_addr = htonl (INADDR_ANY);
23 fd=socket(AF_INET, SOCK_STREAM, 0);
27 printf("createSocket error #1\n");
29 longjmp(error_handler,5);
32 if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) {
36 printf("createSocket error #2\n");
38 longjmp(error_handler, 6);
42 fcntl(fd, F_SETFD, 1);
43 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
47 if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) {
51 printf("createSocket error #3\n");
53 longjmp(error_handler, 7);
57 if (listen(fd, 5)<0) {
61 printf("createSocket error #4\n");
63 longjmp(error_handler, 8);
66 /* Store the fd/socket object mapping */
68 RuntimeHashadd(fdtoobject, fd, (int) VAR(___this___));
74 int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSocket___ * ___this___, struct ___Socket___ * ___s___) {
75 struct sockaddr_in sin;
76 unsigned int sinlen=sizeof(sin);
77 int fd=VAR(___this___)->___fd___;
79 newfd=accept(fd, (struct sockaddr *)&sin, &sinlen);
85 printf("acceptSocket error #1\n");
87 longjmp(error_handler, 9);
90 fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
91 RuntimeHashadd(fdtoobject, newfd, (int) VAR(___s___));
93 flagorand(VAR(___this___),0,0xFFFFFFFE);
100 void CALL02(___Socket______nativeWrite_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
101 int fd=VAR(___this___)->___fd___;
102 int length=VAR(___b___)->___length___;
103 char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int);
105 int bytewritten=write(fd, charstr, length);
106 if (bytewritten==-1&&errno==EAGAIN)
109 if (bytewritten!=length) {
110 perror("ERROR IN NATIVEWRITE");
116 int CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) {
117 int fd=VAR(___this___)->___fd___;
118 int length=VAR(___b___)->___length___;
119 char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int);
120 int byteread=read(fd, charstr, length);
123 printf("ERROR IN NATIVEREAD\n");
126 flagorand(VAR(___this___),0,0xFFFFFFFE);
131 void CALL01(___Socket______nativeClose____, struct ___Socket___ * ___this___) {
132 int fd=VAR(___this___)->___fd___;
135 RuntimeHashget(fdtoobject, fd, &data);
136 RuntimeHashremove(fdtoobject, fd, data);
138 flagorand(VAR(___this___),0,0xFFFFFFFE);