You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@apache.org on 2004/03/14 21:30:20 UTC

cvs commit: apr/test sockchild.c

rbb         2004/03/14 12:30:20

  Added:       test     sockchild.c
  Log:
  I forgot to add sockchild.c, which is required for testsock.
  
  Revision  Changes    Path
  1.1                  apr/test/sockchild.c
  
  Index: sockchild.c
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #include <stdlib.h>
  #include "testsock.h"
  #include "apr_network_io.h"
  #include "apr_pools.h"
  
  int main(int argc, char *argv[])
  {
      apr_pool_t *p;
      apr_socket_t *sock;
      apr_status_t rv;
      apr_sockaddr_t *remote_sa;
  
      apr_initialize();
      atexit(apr_terminate);
      apr_pool_create(&p, NULL);
  
      if (argc < 2) {
          exit(-1);
      }
  
      rv = apr_sockaddr_info_get(&remote_sa, "127.0.0.1", APR_UNSPEC, 8021, 0, p);
      if (rv != APR_SUCCESS) {
          exit(-1);
      }
  
      if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM, 0,
                  p) != APR_SUCCESS) {
          exit(-1);
      }
  
      rv = apr_socket_timeout_set(sock, apr_time_from_sec(3));
      if (rv) {
          exit(-1);
      }
  
      apr_socket_connect(sock, remote_sa);
          
      if (!strcmp("read", argv[1])) {
          char datarecv[STRLEN];
          int length = STRLEN;
  
          apr_status_t rv = apr_socket_recv(sock, datarecv, &length);
          apr_socket_close(sock);
          if (rv == APR_TIMEUP) {
              exit(SOCKET_TIMEOUT); 
          }
  
          if (strcmp(datarecv, DATASTR)) {
              exit(-1);
          }
          
          exit(length);
      }
      else if (!strcmp("write", argv[1])) {
          int length = strlen(DATASTR);
          apr_socket_send(sock, DATASTR, &length);
  
          apr_socket_close(sock);
          exit(length);
      }
      exit(-1);
  }