Ignore:
Timestamp:
Apr 14, 2009, 8:49:12 AM (10 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
cbd1e87
Parents:
c85f252d
Message:

Fixed return codes of open handler.
Request reply after data write connection close.

File:
1 edited

Legend:

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

    rc85f252d r1cb5aa14  
    439439}
    440440
    441 static void rtems_ftpfs_terminate( rtems_libio_t *iop)
    442 {
     441static int rtems_ftpfs_terminate( rtems_libio_t *iop)
     442{
     443  int eno = 0;
     444  int rv = 0;
    443445  rtems_ftpfs_entry *e = iop->data1;
    444446
     
    446448    /* Close data connection if necessary */
    447449    if (e->data_socket >= 0) {
    448       close( e->data_socket);
     450      rv = close( e->data_socket);
     451      if (rv < 0) {
     452        eno = errno;
     453      }
     454
     455      /* For write connections we have to obtain the transfer reply  */
     456      if ((iop->flags & LIBIO_FLAGS_WRITE) != 0 && e->ctrl_socket >= 0) {
     457        rtems_ftpfs_reply reply =
     458          rtems_ftpfs_get_reply( e->ctrl_socket, NULL, NULL);
     459
     460        if (reply != RTEMS_FTPFS_REPLY_2) {
     461          eno = EIO;
     462        }
     463      }
    449464    }
    450465
    451466    /* Close control connection if necessary */
    452467    if (e->ctrl_socket >= 0) {
    453       close( e->ctrl_socket);
     468      rv = close( e->ctrl_socket);
     469      if (rv < 0) {
     470        eno = errno;
     471      }
    454472    }
    455473
     
    460478  /* Invalidate IO entry */
    461479  iop->data1 = NULL;
     480
     481  return eno;
    462482}
    463483
     
    805825  /* Check location, it was allocated during path evaluation */
    806826  if (location == NULL) {
    807     return ENOMEM;
     827    rtems_set_errno_and_return_minus_one( ENOMEM);
    808828  }
    809829
     
    813833      && (iop->flags & LIBIO_FLAGS_READ) != 0
    814834  ) {
    815     return ENOTSUP;
     835    rtems_set_errno_and_return_minus_one( ENOTSUP);
    816836  }
    817837
     
    825845  );
    826846  if (!ok) {
    827     return ENOENT;
     847    rtems_set_errno_and_return_minus_one( ENOENT);
    828848  }
    829849  DEBUG_PRINTF(
     
    837857  e = malloc( sizeof( *e));
    838858  if (e == NULL) {
    839     return ENOMEM;
     859    rtems_set_errno_and_return_minus_one( ENOMEM);
    840860  }
    841861
     
    879899cleanup:
    880900
    881   if (eno != 0) {
     901  if (eno == 0) {
     902    return 0;
     903  } else {
    882904    /* Free all resources if an error occured */
    883905    rtems_ftpfs_terminate( iop);
    884   }
    885 
    886   return eno;
     906
     907    rtems_set_errno_and_return_minus_one( eno);
     908  }
    887909}
    888910
     
    935957  size_t todo = count;
    936958
    937   if (e->eof) {
    938     return 0;
    939   }
    940 
    941959  while (todo > 0) {
    942960    ssize_t rv = send( e->data_socket, out, todo, 0);
     
    944962    if (rv <= 0) {
    945963      if (rv == 0) {
    946         rtems_ftpfs_reply reply =
    947           rtems_ftpfs_get_reply( e->ctrl_socket, NULL, NULL);
    948 
    949         if (reply == RTEMS_FTPFS_REPLY_2) {
    950           e->eof = true;
    951           break;
    952         }
     964        break;
     965      } else {
     966        rtems_set_errno_and_return_minus_one( EIO);
    953967      }
    954 
    955       rtems_set_errno_and_return_minus_one( EIO);
    956968    }
    957969
     
    965977static int rtems_ftpfs_close( rtems_libio_t *iop)
    966978{
    967   rtems_ftpfs_terminate( iop);
    968 
    969   return 0;
     979  int eno = rtems_ftpfs_terminate( iop);
     980
     981  if (eno == 0) {
     982    return 0;
     983  } else {
     984    rtems_set_errno_and_return_minus_one( eno);
     985  }
    970986}
    971987
Note: See TracChangeset for help on using the changeset viewer.