Changeset 521
- Timestamp:
- 01/31/09 15:33:12 (3 years ago)
- Location:
- interpreter/trunk
- Files:
-
- 2 added
- 4 edited
-
ChangeLog (modified) (1 diff)
-
modules/Makefile.am (modified) (1 diff)
-
modules/System/network/socket.c (modified) (5 diffs)
-
modules/all_modules.kt (modified) (2 diffs)
-
modules/interface/pop3.kt (added)
-
modules/interface/smtp.kt (added)
Legend:
- Unmodified
- Added
- Removed
-
interpreter/trunk/ChangeLog
r520 r521 1 1 1/31/2009: 2 2 * Regular expressions can be specified with "r/.../[i]" syntax (ticket #79) 3 * Integrated interface.pop3 and interface.smtp modules (credit: Michael J. Edgar) 3 4 4 5 1/30/2009: -
interpreter/trunk/modules/Makefile.am
r512 r521 20 20 interface/http.kt interface/http/cgi.kt interface/language.kt interface/language/c.kt \ 21 21 interface/text.kt interface/text/readline.kt interface/text/base64.kt \ 22 interface/text/binary.kt all_modules.kt22 interface/text/binary.kt interface/pop3.kt interface/smtp.kt all_modules.kt 23 23 24 24 AM_CFLAGS = -Wdeclaration-after-statement -Werror -Wextra -fno-omit-frame-pointer -ISystem/digest/ -I../objs -I../vm -fPIC -W -Wall -DCINVOKE_BUILD -
interpreter/trunk/modules/System/network/socket.c
r506 r521 122 122 kite_vm_return(thd, kite_new_integer(thd, ret)); 123 123 } 124 125 /***************************************************************************** 126 * Read up to the given number of bytes 127 ****************************************************************************/ 128 KITE_CLASS_METHOD(Socket_read) { 129 kite_object_t *arg1 = args->builtin_data.listvalue.car; 130 kite_object_t *bytes = kite_int_object(thd, arg1); 124 /***************************************************************************** 125 * Read up to the given number of bytes, also with a timeout supplied 126 ****************************************************************************/ 127 KITE_CLASS_METHOD(Socket_read_with_timeout) { 128 129 kite_object_t *bytes; 130 kite_object_t *timeout; 131 struct timeval timeout_struct; 131 132 kite_object_t *rval; 132 char *buf = calloc(bytes->builtin_data.intvalue + 1, 1); 133 int ret; 133 fd_set socklist; 134 135 char *buf; 136 int ret, can_read; 137 138 KITE_GET_METHOD_ARGUMENT(bytes,1); 139 KITE_GET_METHOD_ARGUMENT(timeout, 2); 140 141 buf = calloc(bytes->builtin_data.intvalue + 1, 1); 142 143 timeout_struct.tv_sec = KITE_GET_INTEGER(timeout) / 1000; 144 timeout_struct.tv_usec = (float)(KITE_GET_INTEGER(timeout) % 1000) / 1000.0f; 134 145 135 146 CHECK_SOCKET_OPEN; 136 147 148 149 FD_ZERO(&socklist); 150 FD_SET(KITE_GET_INTEGER(this),&socklist); 151 can_read = select(FD_SETSIZE,&socklist,NULL,NULL,&timeout_struct); 152 if (can_read <= 0) { 153 free(buf); 154 kite_vm_return(thd, kite_new_null(thd)); 155 return; 156 } 157 137 158 ret = read(KITE_GET_INTEGER(this), buf, KITE_GET_STRING_LENGTH(bytes)); 138 159 if (ret < 0 && errno != EAGAIN) { … … 142 163 free(buf); 143 164 kite_vm_return(thd, kite_new_null(thd)); 165 return; 144 166 } 145 167 … … 153 175 kite_vm_return(thd, rval); 154 176 } 177 /***************************************************************************** 178 * Read up to the given number of bytes 179 ****************************************************************************/ 180 KITE_CLASS_METHOD(Socket_read) { 181 kite_object_t *arg1 = args->builtin_data.listvalue.car; 182 kite_object_t *bytes = kite_int_object(thd, arg1); 183 kite_object_t *rval; 184 char *buf = calloc(bytes->builtin_data.intvalue + 1, 1); 185 int ret, can_read; 186 struct timeval timeout; 187 fd_set socklist; 188 189 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 } 202 ret = read(KITE_GET_INTEGER(this), buf, KITE_GET_INTEGER(bytes)); 203 if (ret < 0 && errno != EAGAIN) { 204 free(buf); 205 THROW_SOCKET_ERROR; 206 } else if (ret == 0) { 207 free(buf); 208 kite_vm_return(thd, kite_new_null(thd)); 209 return; 210 } 211 212 rval = kite_new_string_with_length( 213 thd, 214 buf, 215 ret 216 ); 217 free(buf); 218 kite_dereference_object(bytes); 219 kite_vm_return(thd, rval); 220 } 155 221 156 222 /***************************************************************************** … … 161 227 int ret, idx = 0; 162 228 kite_object_t *rval; 229 int can_read; 230 struct timeval timeout; 231 fd_set socklist; 163 232 164 233 CHECK_SOCKET_OPEN; 165 234 KITE_NO_ARGS; 166 235 167 236 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 168 250 do { 169 251 ret = read(KITE_GET_INTEGER(this), &buf[idx], 1); … … 476 558 "Read bytes from socket and place in a string.", 1, 477 559 "size", "Number of bytes to read.")); 560 kite_add_method(thread, newclass, "read", 561 kite_new_method_compiled_with_docs(thread, Socket_read_with_timeout, 562 "Read bytes from socket and place in a string. Takes a timeout argument", 2, 563 "size", "Number of bytes to read.", 564 "timeout", "Number of milliseconds to wait for a connection.")); 478 565 kite_add_method(thread, newclass, "readline", 479 566 kite_new_method_compiled_with_docs(thread, Socket_readline, -
interpreter/trunk/modules/all_modules.kt
r428 r521 31 31 import "System.collections"; 32 32 import "System.date"; 33 import "System.digest"; 33 34 import "System.directory"; 34 35 import "System.doc"; … … 60 61 import "interface.text.base64"; 61 62 import "interface.text.binary"; 63 import "interface.pop3"; 64 import "interface.smtp";
Note: See TracChangeset
for help on using the changeset viewer.
