Changeset 1b508981 in rtems


Ignore:
Timestamp:
May 5, 2009, 12:51:09 PM (10 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
439959b
Parents:
b074e80
Message:

Added timeout for active data connection

accept. Return EIO for close() errors. Changed PORT format string.
Fixed connection termination after store errors on passive connections.
Added magic device identifier for stat().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/lib/ftpfs.c

    rb074e80 r1b508981  
    3535#include <errno.h>
    3636#include <fcntl.h>
    37 #include <inttypes.h>
    3837#include <malloc.h>
    3938#include <netdb.h>
     
    4544#include <arpa/inet.h>
    4645#include <netinet/in.h>
     46#include <sys/select.h>
    4747#include <sys/socket.h>
    4848#include <sys/types.h>
     
    439439}
    440440
    441 static int rtems_ftpfs_terminate( rtems_libio_t *iop)
     441static int rtems_ftpfs_terminate( rtems_libio_t *iop, bool error)
    442442{
    443443  int eno = 0;
     
    449449    if (e->data_socket >= 0) {
    450450      rv = close( e->data_socket);
    451       if (rv < 0) {
    452         eno = errno;
     451      if (rv != 0) {
     452        eno = EIO;
    453453      }
    454454
    455455      /* For write connections we have to obtain the transfer reply  */
    456       if ((iop->flags & LIBIO_FLAGS_WRITE) != 0 && e->ctrl_socket >= 0) {
     456      if (
     457        e->ctrl_socket >= 0
     458          && (iop->flags & LIBIO_FLAGS_WRITE) != 0
     459          && !error
     460      ) {
    457461        rtems_ftpfs_reply reply =
    458462          rtems_ftpfs_get_reply( e->ctrl_socket, NULL, NULL);
     
    467471    if (e->ctrl_socket >= 0) {
    468472      rv = close( e->ctrl_socket);
    469       if (rv < 0) {
    470         eno = errno;
     473      if (rv != 0) {
     474        eno = EIO;
    471475      }
    472476    }
     
    586590  char port_command [] = "PORT 000,000,000,000,000,000";
    587591  uint16_t data_port = 0;
     592  fd_set fds;
     593  struct timeval timeout = {
     594    .tv_sec = 60,
     595    .tv_usec = 0
     596  };
    588597
    589598  /* Create port socket to establish a data data connection */
     
    623632    port_command,
    624633    sizeof( port_command),
    625     "PORT %" PRIu32 ",%" PRIu32 ",%" PRIu32 ",%" PRIu32 ",%" PRIu16 ",%" PRIu16,
    626     (client_address >> 24) & 0xff,
    627     (client_address >> 16) & 0xff,
    628     (client_address >> 8) & 0xff,
    629     (client_address >> 0) & 0xff,
    630     (data_port >> 8) & 0xff,
    631     (data_port >> 0) & 0xff
     634    "PORT %lu,%lu,%lu,%lu,%lu,%lu",
     635    (client_address >> 24) & 0xffUL,
     636    (client_address >> 16) & 0xffUL,
     637    (client_address >> 8) & 0xffUL,
     638    (client_address >> 0) & 0xffUL,
     639    (data_port >> 8) & 0xffUL,
     640    (data_port >> 0) & 0xffUL
    632641  );
    633642  reply = rtems_ftpfs_send_command( e->ctrl_socket, port_command, NULL);
     
    651660  }
    652661
    653   /*
    654    * Wait for connect on data connection.
    655    *
    656    * FIXME: This should become a select instead with a timeout.
    657    */
     662  /* Wait for connect on data connection  */
     663  FD_ZERO( &fds);
     664  FD_SET( port_socket, &fds);
     665  rv = select( port_socket + 1, &fds, NULL, NULL, &timeout);
     666  if (rv <= 0) {
     667    eno = EIO;
     668    goto cleanup;
     669  }
     670
     671  /* Accept data connection  */
    658672  size = sizeof( sa);
    659673  e->data_socket = accept(
     
    667681  }
    668682
    669   /* FIXME: Check, that server data address is really from our server  */
    670 
    671683cleanup:
    672684
    673685  /* Close port socket if necessary */
    674686  if (port_socket >= 0) {
    675     close( port_socket);
     687    rv = close( port_socket);
     688    if (rv != 0) {
     689      eno = EIO;
     690    }
    676691  }
    677692
     
    903918  } else {
    904919    /* Free all resources if an error occured */
    905     rtems_ftpfs_terminate( iop);
     920    rtems_ftpfs_terminate( iop, true);
    906921
    907922    rtems_set_errno_and_return_minus_one( eno);
     
    977992static int rtems_ftpfs_close( rtems_libio_t *iop)
    978993{
    979   int eno = rtems_ftpfs_terminate( iop);
     994  int eno = rtems_ftpfs_terminate( iop, false);
    980995
    981996  if (eno == 0) {
     
    10611076  /* FIXME */
    10621077  st->st_ino = ++ino;
     1078  st->st_dev = rtems_filesystem_make_dev_t( 0xcc494cd6U, 0x1d970b4dU);
    10631079
    10641080  st->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
Note: See TracChangeset for help on using the changeset viewer.