Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ftp_timeout.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (show annotations) (download) (as text)
Wed Dec 2 15:13:30 2009 UTC (14 years, 3 months ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 2235 byte(s)
add error check
1 /*
2 liboftp: this is an FTP library to simplify the work to a Developer
3 who want to work with FTP servers (RFC 959).
4
5 Copyright (c) 2009 hirohito higashi. All rights reserved.
6 This file is distributed under BSD license.
7 */
8
9
10 /***** Feature test switches ************************************************/
11 /***** System headers *******************************************************/
12 #include <sys/time.h>
13 #include <sys/types.h>
14 #include <sys/socket.h>
15
16
17 /***** Local headers ********************************************************/
18 #include "liboftp.h"
19 #include "sub.h"
20
21
22 /***** Constat values *******************************************************/
23 /***** Macros ***************************************************************/
24 /***** Typedefs *************************************************************/
25 /***** Function prototypes **************************************************/
26 /***** Local variables ******************************************************/
27 /***** Global variables *****************************************************/
28 /***** Signal catching functions ********************************************/
29 /***** Local functions ******************************************************/
30 /***** Global functions *****************************************************/
31
32 /****************************************************************************/
33 /*! ������������������������������
34 *
35 *@param ftp LIBOFTP���������������������
36 *@param sec ���������������������������������
37 *@retval int ������������������
38 *@note
39 */
40 int ftp_timeout( LIBOFTP *ftp, int sec )
41 {
42 struct timeval tval;
43
44 ftp->timeout_sec = sec;
45 if( ftp->socket < 0 ) {
46 return LIBOFTP_NOERROR;
47 }
48
49 tval.tv_sec = ftp->timeout_sec;
50 tval.tv_usec = 0;
51 if( setsockopt( ftp->socket, SOL_SOCKET, SO_SNDTIMEO, &tval, sizeof(struct timeval) ) < 0 ) {
52 DEBUGPRINT1( "setsockopt(SO_SNDTIMEO) failed. %s\n", strerror(errno) );
53 copy_strerror();
54 return LIBOFTP_ERROR_OS;
55 }
56 if( setsockopt( ftp->socket, SOL_SOCKET, SO_RCVTIMEO, &tval, sizeof(struct timeval) ) < 0 ) {
57 DEBUGPRINT1( "setsockopt(SO_RCVTIMEO) failed. %s\n", strerror(errno) );
58 copy_strerror();
59 return LIBOFTP_ERROR_OS;
60 }
61
62 return LIBOFTP_NOERROR;
63 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26