Changeset 521


Ignore:
Timestamp:
01/31/09 15:33:12 (3 years ago)
Author:
mooneer
Message:

Integrated interface.pop3 and interface.smtp modules (credit: Michael J. Edgar)

Location:
interpreter/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • interpreter/trunk/ChangeLog

    r520 r521  
    111/31/2009: 
    22    * Regular expressions can be specified with "r/.../[i]" syntax (ticket #79) 
     3    * Integrated interface.pop3 and interface.smtp modules (credit: Michael J. Edgar) 
    34 
    451/30/2009: 
  • interpreter/trunk/modules/Makefile.am

    r512 r521  
    2020        interface/http.kt interface/http/cgi.kt interface/language.kt interface/language/c.kt \ 
    2121        interface/text.kt interface/text/readline.kt interface/text/base64.kt \ 
    22         interface/text/binary.kt all_modules.kt 
     22        interface/text/binary.kt interface/pop3.kt interface/smtp.kt all_modules.kt 
    2323 
    2424AM_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  
    122122    kite_vm_return(thd, kite_new_integer(thd, ret)); 
    123123} 
    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 ****************************************************************************/ 
     127KITE_CLASS_METHOD(Socket_read_with_timeout) { 
     128     
     129    kite_object_t *bytes; 
     130    kite_object_t *timeout; 
     131    struct timeval timeout_struct; 
    131132    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; 
    134145 
    135146    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     
    137158    ret = read(KITE_GET_INTEGER(this), buf, KITE_GET_STRING_LENGTH(bytes)); 
    138159    if (ret < 0 && errno != EAGAIN) { 
     
    142163        free(buf); 
    143164        kite_vm_return(thd, kite_new_null(thd)); 
     165        return; 
    144166    } 
    145167 
     
    153175    kite_vm_return(thd, rval); 
    154176} 
     177/***************************************************************************** 
     178 * Read up to the given number of bytes 
     179 ****************************************************************************/ 
     180KITE_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} 
    155221 
    156222/***************************************************************************** 
     
    161227    int ret, idx = 0; 
    162228    kite_object_t *rval; 
     229    int can_read; 
     230    struct timeval timeout; 
     231    fd_set socklist; 
    163232 
    164233    CHECK_SOCKET_OPEN; 
    165234    KITE_NO_ARGS; 
    166      
     235 
    167236    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     
    168250    do { 
    169251        ret = read(KITE_GET_INTEGER(this), &buf[idx], 1); 
     
    476558                                  "Read bytes from socket and place in a string.", 1, 
    477559                                  "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.")); 
    478565    kite_add_method(thread, newclass, "readline",  
    479566        kite_new_method_compiled_with_docs(thread, Socket_readline,  
  • interpreter/trunk/modules/all_modules.kt

    r428 r521  
    3131import "System.collections"; 
    3232import "System.date"; 
     33import "System.digest"; 
    3334import "System.directory"; 
    3435import "System.doc"; 
     
    6061import "interface.text.base64"; 
    6162import "interface.text.binary"; 
     63import "interface.pop3"; 
     64import "interface.smtp"; 
Note: See TracChangeset for help on using the changeset viewer.