If the close() is successful, set the fd to -1.

2001-01-15  Jeffrey Stedfast  <fejj@ximian.com>

	* camel-stream-fs.c (stream_close): If the close() is successful,
	set the fd to -1.

	* camel-tcp-stream-raw.c: Removed the disconnect() method.
	(stream_close): If the close() is successful, set the sockfd to
	-1.

	* camel-tcp-stream-ssl.c: Removed the disconnect() method.
	(stream_close): If the close() is successful, set the sockfd to
	NULL.

	* camel-tcp-stream.c (camel_tcp_stream_disconnect): Removed,
	easier to just use the close() method as it did the same thing
	anyway.

svn path=/trunk/; revision=7522
This commit is contained in:
Jeffrey Stedfast
2001-01-16 00:54:18 +00:00
committed by Jeffrey Stedfast
parent baffaa5769
commit d9b76e981f
6 changed files with 34 additions and 50 deletions

View File

@ -1,3 +1,20 @@
2001-01-15 Jeffrey Stedfast <fejj@ximian.com>
* camel-stream-fs.c (stream_close): If the close() is successful,
set the fd to -1.
* camel-tcp-stream-raw.c: Removed the disconnect() method.
(stream_close): If the close() is successful, set the sockfd to
-1.
* camel-tcp-stream-ssl.c: Removed the disconnect() method.
(stream_close): If the close() is successful, set the sockfd to
NULL.
* camel-tcp-stream.c (camel_tcp_stream_disconnect): Removed,
easier to just use the close() method as it did the same thing
anyway.
2001-01-15 Jeffrey Stedfast <fejj@ximian.com>
* camel-tcp-stream-raw.c (stream_getsockopt): Updated to be able

View File

@ -313,7 +313,11 @@ stream_flush (CamelStream *stream)
static int
stream_close (CamelStream *stream)
{
return close(((CamelStreamFs *)stream)->fd);
if (close (((CamelStreamFs *)stream)->fd) == -1)
return -1;
((CamelStreamFs *)stream)->fd= -1;
return 0;
}
static off_t

View File

@ -41,7 +41,6 @@ static int stream_flush (CamelStream *stream);
static int stream_close (CamelStream *stream);
static int stream_connect (CamelTcpStream *stream, struct hostent *host, int port);
static int stream_disconnect (CamelTcpStream *stream);
static int stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data);
static int stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data);
@ -62,7 +61,6 @@ camel_tcp_stream_raw_class_init (CamelTcpStreamRawClass *camel_tcp_stream_raw_cl
camel_stream_class->close = stream_close;
camel_tcp_stream_class->connect = stream_connect;
camel_tcp_stream_class->disconnect = stream_disconnect;
camel_tcp_stream_class->getsockopt = stream_getsockopt;
camel_tcp_stream_class->setsockopt = stream_setsockopt;
}
@ -160,8 +158,11 @@ stream_flush (CamelStream *stream)
static int
stream_close (CamelStream *stream)
{
g_warning ("CamelTcpStreamRaw::close: Better to call ::disconnect.\n");
return close (((CamelTcpStreamRaw *)stream)->sockfd);
if (close (((CamelTcpStreamRaw *)stream)->sockfd) == -1)
return -1;
((CamelTcpStreamRaw *)stream)->sockfd = -1;
return 0;
}
@ -193,12 +194,6 @@ stream_connect (CamelTcpStream *stream, struct hostent *host, int port)
return 0;
}
static int
stream_disconnect (CamelTcpStream *stream)
{
return close (((CamelTcpStreamRaw *)stream)->sockfd);
}
static int
get_sockopt_level (const CamelSockOptData *data)
@ -268,7 +263,7 @@ stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
static int
stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
{
int optname, optlen;
int optname;
if ((optname = get_sockopt_optname (data)) == -1)
return -1;

View File

@ -41,7 +41,6 @@ static int stream_flush (CamelStream *stream);
static int stream_close (CamelStream *stream);
static int stream_connect (CamelTcpStream *stream, struct hostent *host, int port);
static int stream_disconnect (CamelTcpStream *stream);
static int stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data);
static int stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data);
@ -62,7 +61,6 @@ camel_tcp_stream_ssl_class_init (CamelTcpStreamSSLClass *camel_tcp_stream_ssl_cl
camel_stream_class->close = stream_close;
camel_tcp_stream_class->connect = stream_connect;
camel_tcp_stream_class->disconnect = stream_disconnect;
camel_tcp_stream_class->getsockopt = stream_getsockopt;
camel_tcp_stream_class->setsockopt = stream_setsockopt;
}
@ -160,8 +158,12 @@ stream_flush (CamelStream *stream)
static int
stream_close (CamelStream *stream)
{
g_warning ("CamelTcpStreamSSL::close called on a stream where ::disconnect is preferred\n");
return PR_Close (((CamelTcpStreamSSL *)stream)->sockfd);
if (PR_Close (((CamelTcpStreamSSL *)stream)->sockfd) == PR_Failure)
return -1;
((CamelTcpStreamSSL *)stream)->sockfd = NULL;
return 0;
}
@ -196,11 +198,6 @@ stream_connect (CamelTcpStream *stream, struct hostent *host, int port)
return 0;
}
static int
stream_disconnect (CamelTcpStream *stream)
{
return PR_Close (((CamelTcpStreamSSL *)stream)->sockfd);
}
static int
stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)

View File

@ -31,7 +31,6 @@ static CamelStreamClass *parent_class = NULL;
#define CTS_CLASS(so) CAMEL_TCP_STREAM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
static int tcp_connect (CamelTcpStream *stream, struct hostent *host, int port);
static int tcp_disconnect (CamelTcpStream *stream);
static int tcp_getsockopt (CamelTcpStream *stream, CamelSockOptData *data);
static int tcp_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data);
@ -45,7 +44,6 @@ camel_tcp_stream_class_init (CamelTcpStreamClass *camel_tcp_stream_class)
/* tcp stream methods */
camel_tcp_stream_class->connect = tcp_connect;
camel_tcp_stream_class->disconnect = tcp_disconnect;
camel_tcp_stream_class->getsockopt = tcp_getsockopt;
camel_tcp_stream_class->setsockopt = tcp_setsockopt;
}
@ -102,31 +100,6 @@ camel_tcp_stream_connect (CamelTcpStream *stream, struct hostent *host, int port
}
static int
tcp_disconnect (CamelTcpStream *stream)
{
g_warning ("CamelTcpStream::disconnect called on default implementation\n");
return -1;
}
/**
* camel_tcp_stream_disconnect:
* @stream: tcp stream object
*
* Disconnect the tcp stream and properly close the socket.
*
* Return value: zero on success or -1 on fail.
**/
int
camel_tcp_stream_disconnect (CamelTcpStream *stream)
{
g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), -1);
return CTS_CLASS (stream)->disconnect (stream);
}
static int
tcp_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
{

View File

@ -97,7 +97,6 @@ typedef struct {
/* Virtual methods */
int (*connect) (CamelTcpStream *stream, struct hostent *host, int port);
int (*disconnect) (CamelTcpStream *stream);
int (*getsockopt) (CamelTcpStream *stream, CamelSockOptData *data);
int (*setsockopt) (CamelTcpStream *stream, const CamelSockOptData *data);
@ -108,7 +107,6 @@ CamelType camel_tcp_stream_get_type (void);
/* public methods */
int camel_tcp_stream_connect (CamelTcpStream *stream, struct hostent *host, int port);
int camel_tcp_stream_disconnect (CamelTcpStream *stream);
int camel_tcp_stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data);
int camel_tcp_stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data);