mturk       2005/04/13 06:17:42

  Modified:    jni/native/src network.c poll.c
  Log:
  Add offset for send and receive oprations to skip the need for array copy.
  
  Revision  Changes    Path
  1.3       +54 -8     jakarta-tomcat-connectors/jni/native/src/network.c
  
  Index: network.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/network.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- network.c 5 Feb 2005 12:33:09 -0000       1.2
  +++ network.c 13 Apr 2005 13:17:42 -0000      1.3
  @@ -173,7 +173,7 @@
   }
   
   TCN_IMPLEMENT_CALL(jint, Socket, send)(TCN_STDARGS, jlong sock,
  -                                      jbyteArray buf, jint tosend)
  +                                      jbyteArray buf, jint offset, jint 
tosend)
   {
       apr_socket_t *s = J2P(sock, apr_socket_t *);
       apr_size_t nbytes = (*e)->GetArrayLength(e, buf);
  @@ -188,7 +188,7 @@
            bytes = (*e)->GetPrimitiveArrayCritical(e, buf, NULL);
       else
            bytes = (*e)->GetByteArrayElements(e, buf, NULL);
  -    TCN_THROW_IF_ERR(apr_socket_send(s, bytes, &nbytes), nbytes);
  +    TCN_THROW_IF_ERR(apr_socket_send(s, bytes + offset, &nbytes), nbytes);
   
   cleanup:
       if (nb)
  @@ -198,6 +198,28 @@
       return (jint)nbytes;
   }
   
  +TCN_IMPLEMENT_CALL(jint, Socket, sendb)(TCN_STDARGS, jlong sock,
  +                                        jobject buf, jint offset, jint len)
  +{
  +    apr_socket_t *s = J2P(sock, apr_socket_t *);
  +    apr_size_t nbytes;
  +    char *bytes;
  +
  +    UNREFERENCED(o);
  +    bytes  = (char *)(*e)->GetDirectBufferAddress(e, buf);
  +    nbytes = (apr_size_t)(*e)->GetDirectBufferCapacity(e, buf);
  +    if (bytes == NULL || nbytes < 0) {
  +        tcn_ThrowAPRException(e, APR_EGENERAL);
  +        goto cleanup;
  +    }
  +    if (len > 0)
  +        nbytes = min(nbytes, (apr_size_t)len);
  +    TCN_THROW_IF_ERR(apr_socket_send(s, bytes + offset, &nbytes), nbytes);
  +
  +cleanup:
  +    return (jint)nbytes;
  +}
  +
   TCN_IMPLEMENT_CALL(jint, Socket, sendv)(TCN_STDARGS, jlong sock,
                                           jobjectArray bufs)
   {
  @@ -231,7 +253,7 @@
   
   TCN_IMPLEMENT_CALL(jint, Socket, sendto)(TCN_STDARGS, jlong sock,
                                            jlong where, jint flag,
  -                                         jbyteArray buf, jint tosend)
  +                                         jbyteArray buf, jint offset, jint 
tosend)
   {
       apr_socket_t *s = J2P(sock, apr_socket_t *);
       apr_sockaddr_t *w = J2P(where, apr_sockaddr_t *);
  @@ -247,7 +269,7 @@
            bytes = (*e)->GetPrimitiveArrayCritical(e, buf, NULL);
       else
            bytes = (*e)->GetByteArrayElements(e, buf, NULL);
  -    TCN_THROW_IF_ERR(apr_socket_sendto(s, w, flag, bytes, &nbytes), nbytes);
  +    TCN_THROW_IF_ERR(apr_socket_sendto(s, w, flag, bytes + offset, &nbytes), 
nbytes);
   
   cleanup:
       if (nb)
  @@ -258,7 +280,7 @@
   }
   
   TCN_IMPLEMENT_CALL(jint, Socket, recv)(TCN_STDARGS, jlong sock,
  -                                       jbyteArray buf, jint toread)
  +                                       jbyteArray buf, jint offset, jint 
toread)
   {
       apr_socket_t *s = J2P(sock, apr_socket_t *);
       apr_size_t nbytes = (*e)->GetArrayLength(e, buf);
  @@ -268,7 +290,7 @@
       if (toread > 0)
           nbytes = min(nbytes, (apr_size_t)toread);
   
  -    TCN_THROW_IF_ERR(apr_socket_recv(s, bytes, &nbytes), nbytes);
  +    TCN_THROW_IF_ERR(apr_socket_recv(s, bytes + offset, &nbytes), nbytes);
   
   cleanup:
       (*e)->ReleaseByteArrayElements(e, buf, bytes,
  @@ -276,9 +298,33 @@
       return (jint)nbytes;
   }
   
  +TCN_IMPLEMENT_CALL(jint, Socket, recvb)(TCN_STDARGS, jlong sock,
  +                                        jobject buf, jint offset, jint len)
  +{
  +    apr_socket_t *s = J2P(sock, apr_socket_t *);
  +
  +    apr_size_t nbytes;
  +    char *bytes;
  +
  +    UNREFERENCED(o);
  +    bytes  = (char *)(*e)->GetDirectBufferAddress(e, buf);
  +    nbytes = (apr_size_t)(*e)->GetDirectBufferCapacity(e, buf);
  +    if (bytes == NULL || nbytes < 0) {
  +        tcn_ThrowAPRException(e, APR_EGENERAL);
  +        goto cleanup;
  +    }
  +    if (len > 0)
  +        nbytes = min(nbytes, (apr_size_t)len);
  +
  +    TCN_THROW_IF_ERR(apr_socket_recv(s, bytes + offset, &nbytes), nbytes);
  +
  +cleanup:
  +    return (jint)nbytes;
  +}
  +
   TCN_IMPLEMENT_CALL(jint, Socket, recvfrom)(TCN_STDARGS, jlong from,
                                             jlong sock, jint flags,
  -                                          jbyteArray buf, jint toread)
  +                                          jbyteArray buf, jint offset, jint 
toread)
   {
       apr_socket_t *s = J2P(sock, apr_socket_t *);
       apr_sockaddr_t *f = J2P(from, apr_sockaddr_t *);
  @@ -290,7 +336,7 @@
           nbytes = min(nbytes, (apr_size_t)toread);
   
       TCN_THROW_IF_ERR(apr_socket_recvfrom(f, s,
  -            (apr_int32_t)flags, bytes, &nbytes), nbytes);
  +            (apr_int32_t)flags, bytes + offset, &nbytes), nbytes);
   
   cleanup:
       (*e)->ReleaseByteArrayElements(e, buf, bytes,
  
  
  
  1.3       +1 -2      jakarta-tomcat-connectors/jni/native/src/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/poll.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- poll.c    5 Feb 2005 12:32:36 -0000       1.2
  +++ poll.c    13 Apr 2005 13:17:42 -0000      1.3
  @@ -46,7 +46,7 @@
   
   TCN_IMPLEMENT_CALL(jint, Poll, add)(TCN_STDARGS, jlong pollset,
                                       jlong socket, jlong data,
  -                                    jint reqevents, jint rtnevents)
  +                                    jint reqevents)
   {
       apr_pollset_t *p = J2P(pollset,  apr_pollset_t *);
       apr_pollfd_t fd;
  @@ -56,7 +56,6 @@
       memset(&fd, 0, sizeof(apr_pollfd_t));
       fd.desc_type = APR_POLL_SOCKET;
       fd.reqevents = (apr_int16_t)reqevents;
  -    fd.rtnevents = (apr_int16_t)rtnevents;
       fd.desc.s = J2P(socket, apr_socket_t *);
       fd.client_data = J2P(data, void *);
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to