Changeset 538
- Timestamp:
- 02/07/09 15:41:55 (3 years ago)
- Location:
- interpreter/trunk/modules
- Files:
-
- 2 edited
-
System/network/socket.c (modified) (5 diffs)
-
all_modules.kt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
interpreter/trunk/modules/System/network/socket.c
r521 r538 175 175 kite_vm_return(thd, rval); 176 176 } 177 /************************************************************************* 178 * Check if the socket has data. 179 ****************************************************************************/ 180 KITE_CLASS_METHOD(Socket_eof) { 181 kite_object_t *timeout; 182 struct timeval timeout_struct; 183 fd_set socklist; 184 185 int can_read; 186 187 KITE_GET_METHOD_ARGUMENT(timeout, 1); 188 if (timeout == NULL || timeout->type == OBJ_NULL) { 189 timeout_struct.tv_sec = 1; 190 timeout_struct.tv_usec = 0; 191 } 192 else 193 { 194 timeout_struct.tv_sec = KITE_GET_INTEGER(timeout) / 1000; 195 timeout_struct.tv_usec = (float)(KITE_GET_INTEGER(timeout) % 1000) / 1000.0f; 196 } 197 198 CHECK_SOCKET_OPEN; 199 200 FD_ZERO(&socklist); 201 FD_SET(KITE_GET_INTEGER(this),&socklist); 202 can_read = select(FD_SETSIZE,&socklist,NULL,NULL,&timeout_struct); 203 if (can_read <= 0) { 204 kite_vm_return(thd, kite_new_boolean(thd,TRUE)); 205 return; 206 } 207 else { 208 kite_vm_return(thd, kite_new_boolean(thd,FALSE)); 209 return; 210 } 211 } 177 212 /***************************************************************************** 178 213 * Read up to the given number of bytes … … 183 218 kite_object_t *rval; 184 219 char *buf = calloc(bytes->builtin_data.intvalue + 1, 1); 185 int ret, can_read; 186 struct timeval timeout; 187 fd_set socklist; 220 int ret; 188 221 189 222 CHECK_SOCKET_OPEN; 190 191 timeout.tv_sec = 1; 192 timeout.tv_usec = 0; 193 194 FD_ZERO(&socklist); 195 FD_SET(KITE_GET_INTEGER(this),&socklist); 196 can_read = select(FD_SETSIZE,&socklist,NULL,NULL,&timeout); 197 if (can_read <= 0) { 198 free(buf); 199 kite_vm_return(thd, kite_new_null(thd)); 200 return; 201 } 223 202 224 ret = read(KITE_GET_INTEGER(this), buf, KITE_GET_INTEGER(bytes)); 203 225 if (ret < 0 && errno != EAGAIN) { … … 227 249 int ret, idx = 0; 228 250 kite_object_t *rval; 229 int can_read;230 struct timeval timeout;231 fd_set socklist;251 // int can_read; 252 // struct timeval timeout; 253 // fd_set socklist; 232 254 233 255 CHECK_SOCKET_OPEN; … … 235 257 236 258 buf = calloc(1, 1); 237 238 timeout.tv_sec = 1; 239 timeout.tv_usec = 0; 240 241 FD_ZERO(&socklist); 242 FD_SET(KITE_GET_INTEGER(this),&socklist); 243 can_read = select(FD_SETSIZE,&socklist,NULL,NULL,&timeout); 244 if (can_read <= 0) { 245 free(buf); 246 kite_vm_return(thd, kite_new_null(thd)); 247 return; 248 } 249 259 250 260 do { 251 261 ret = read(KITE_GET_INTEGER(this), &buf[idx], 1); … … 554 564 "Listen for connections on given socket.", 1, 555 565 "queue", "The size of the listen queue.")); 566 kite_add_method(thread, newclass, "eof", 567 kite_new_method_compiled_with_docs(thread, Socket_eof, 568 "Checks if the socket has any more data to read. 1 second timeout.", 0)); 569 kite_add_method(thread, newclass, "eof", 570 kite_new_method_compiled_with_docs(thread, Socket_eof, 571 "Checks if the socket has any more data to read. Timeout in parameter.", 1, 572 "timeout","How long (in milliseconds) to wait before timing out and returning TRUE.")); 556 573 kite_add_method(thread, newclass, "read", 557 574 kite_new_method_compiled_with_docs(thread, Socket_read, -
interpreter/trunk/modules/all_modules.kt
r522 r538 30 30 import "System.boolean"; 31 31 import "System.collections"; 32 import "System.collections.array"; 32 33 import "System.date"; 33 34 import "System.date.hires";
Note: See TracChangeset
for help on using the changeset viewer.
