[evolution-data-server/camel-socks-proxy] Move CamelTcpStreamRaw's fields to a private structure
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/camel-socks-proxy] Move CamelTcpStreamRaw's fields to a private structure
- Date: Thu, 15 Jul 2010 02:22:49 +0000 (UTC)
commit f23b1600ab4e9dcac005ef4045e7c78c4f6f9182
Author: Federico Mena Quintero <federico novell com>
Date: Wed Jul 14 16:06:56 2010 -0500
Move CamelTcpStreamRaw's fields to a private structure
We also add a temporary camel_tcp_stream_raw_get_fd(), used by the imapx provider.
This function will go away in favor of the general camel_tcp_stream_get_file_desc().
Signed-off-by: Federico Mena Quintero <federico novell com>
camel/camel-tcp-stream-raw.c | 79 ++++++++++++++++++++-------
camel/camel-tcp-stream-raw.h | 7 +--
camel/providers/imapx/camel-imapx-server.c | 2 +-
3 files changed, 62 insertions(+), 26 deletions(-)
---
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c
index 0f69050..851d15a 100644
--- a/camel/camel-tcp-stream-raw.c
+++ b/camel/camel-tcp-stream-raw.c
@@ -37,6 +37,13 @@
#include "camel-operation.h"
#include "camel-tcp-stream-raw.h"
+typedef struct _CamelTcpStreamRawPrivate {
+ gint sockfd;
+#ifdef G_OS_WIN32
+ gint is_nonblocking;
+#endif
+} CamelTcpStreamRawPrivate;
+
#ifndef G_OS_WIN32
#define SOCKET_ERROR_CODE() errno
#define SOCKET_CLOSE(fd) close (fd)
@@ -94,17 +101,25 @@ static void
camel_tcp_stream_raw_init (gpointer object, gpointer klass)
{
CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object);
+ CamelTcpStreamRawPrivate *priv;
- stream->sockfd = -1;
+ stream->priv = g_new0 (CamelTcpStreamRawPrivate, 1);
+ priv = stream->priv;
+
+ priv->sockfd = -1;
}
static void
camel_tcp_stream_raw_finalize (CamelObject *object)
{
- CamelTcpStreamRaw *stream = CAMEL_TCP_STREAM_RAW (object);
+ CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (object);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
- if (stream->sockfd != -1)
- SOCKET_CLOSE (stream->sockfd);
+ if (priv->sockfd != -1)
+ SOCKET_CLOSE (priv->sockfd);
+
+ g_free (raw->priv);
+ raw->priv = NULL;
}
CamelType
@@ -248,16 +263,18 @@ static gssize
stream_read (CamelStream *stream, gchar *buffer, gsize n)
{
CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
- return camel_read_socket (raw->sockfd, buffer, n);
+ return camel_read_socket (priv->sockfd, buffer, n);
}
static gssize
stream_write (CamelStream *stream, const gchar *buffer, gsize n)
{
CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
- return camel_write_socket (raw->sockfd, buffer, n);
+ return camel_write_socket (priv->sockfd, buffer, n);
}
static gint
@@ -269,10 +286,13 @@ stream_flush (CamelStream *stream)
static gint
stream_close (CamelStream *stream)
{
- if (SOCKET_CLOSE (((CamelTcpStreamRaw *)stream)->sockfd) == -1)
+ CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
+
+ if (SOCKET_CLOSE (priv->sockfd) == -1)
return -1;
- ((CamelTcpStreamRaw *)stream)->sockfd = -1;
+ priv->sockfd = -1;
return 0;
}
@@ -479,6 +499,7 @@ static gint
stream_connect (CamelTcpStream *stream, const char *host, const char *service, gint fallback_port, CamelException *ex)
{
CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
struct addrinfo *addr, *ai;
struct addrinfo hints;
CamelException my_ex;
@@ -511,11 +532,11 @@ stream_connect (CamelTcpStream *stream, const char *host, const char *service, g
while (ai) {
if (proxy_host)
- raw->sockfd = connect_to_socks4_proxy (proxy_host, proxy_port, ai);
+ priv->sockfd = connect_to_socks4_proxy (proxy_host, proxy_port, ai);
else
- raw->sockfd = socket_connect (ai);
+ priv->sockfd = socket_connect (ai);
- if (raw->sockfd != -1) {
+ if (priv->sockfd != -1) {
retval = 0;
goto out;
}
@@ -576,6 +597,8 @@ get_sockopt_optname (const CamelSockOptData *data)
static gint
stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
{
+ CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
gint optname, optlen;
if ((optname = get_sockopt_optname (data)) == -1)
@@ -585,18 +608,18 @@ stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
#ifndef G_OS_WIN32
gint flags;
- flags = fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_GETFL);
+ flags = fcntl (priv->sockfd, F_GETFL);
if (flags == -1)
return -1;
data->value.non_blocking = flags & O_NONBLOCK ? TRUE : FALSE;
#else
- data->value.non_blocking = ((CamelTcpStreamRaw *)stream)->is_nonblocking;
+ data->value.non_blocking = priv->is_nonblocking;
#endif
return 0;
}
- return getsockopt (((CamelTcpStreamRaw *)stream)->sockfd,
+ return getsockopt (priv->sockfd,
get_sockopt_level (data),
optname,
(gpointer) &data->value,
@@ -606,6 +629,8 @@ stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
static gint
stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
{
+ CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
gint optname;
if ((optname = get_sockopt_optname (data)) == -1)
@@ -615,25 +640,25 @@ stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
#ifndef G_OS_WIN32
gint flags, set;
- flags = fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_GETFL);
+ flags = fcntl (priv->sockfd, F_GETFL);
if (flags == -1)
return -1;
set = data->value.non_blocking ? O_NONBLOCK : 0;
flags = (flags & ~O_NONBLOCK) | set;
- if (fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_SETFL, flags) == -1)
+ if (fcntl (priv->sockfd, F_SETFL, flags) == -1)
return -1;
#else
u_long fionbio = data->value.non_blocking ? 1 : 0;
- if (ioctlsocket (((CamelTcpStreamRaw *)stream)->sockfd, FIONBIO, &fionbio) == SOCKET_ERROR)
+ if (ioctlsocket (priv->sockfd, FIONBIO, &fionbio) == SOCKET_ERROR)
return -1;
- ((CamelTcpStreamRaw *)stream)->is_nonblocking = data->value.non_blocking ? 1 : 0;
+ priv->is_nonblocking = data->value.non_blocking ? 1 : 0;
#endif
return 0;
}
- return setsockopt (((CamelTcpStreamRaw *)stream)->sockfd,
+ return setsockopt (priv->sockfd,
get_sockopt_level (data),
optname,
(gpointer) &data->value,
@@ -643,6 +668,8 @@ stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
static struct sockaddr *
stream_get_local_address (CamelTcpStream *stream, socklen_t *len)
{
+ CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
#ifdef ENABLE_IPv6
struct sockaddr_in6 sin;
#else
@@ -651,7 +678,7 @@ stream_get_local_address (CamelTcpStream *stream, socklen_t *len)
struct sockaddr *saddr = (struct sockaddr *)&sin;
*len = sizeof(sin);
- if (getsockname (CAMEL_TCP_STREAM_RAW (stream)->sockfd, saddr, len) == -1)
+ if (getsockname (priv->sockfd, saddr, len) == -1)
return NULL;
saddr = g_malloc(*len);
@@ -663,6 +690,8 @@ stream_get_local_address (CamelTcpStream *stream, socklen_t *len)
static struct sockaddr *
stream_get_remote_address (CamelTcpStream *stream, socklen_t *len)
{
+ CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream);
+ CamelTcpStreamRawPrivate *priv = raw->priv;
#ifdef ENABLE_IPv6
struct sockaddr_in6 sin;
#else
@@ -671,7 +700,7 @@ stream_get_remote_address (CamelTcpStream *stream, socklen_t *len)
struct sockaddr *saddr = (struct sockaddr *)&sin;
*len = sizeof(sin);
- if (getpeername (CAMEL_TCP_STREAM_RAW (stream)->sockfd, saddr, len) == -1)
+ if (getpeername (priv->sockfd, saddr, len) == -1)
return NULL;
saddr = g_malloc(*len);
@@ -679,3 +708,11 @@ stream_get_remote_address (CamelTcpStream *stream, socklen_t *len)
return saddr;
}
+
+gint
+camel_tcp_stream_raw_get_fd (CamelTcpStreamRaw *raw)
+{
+ CamelTcpStreamRawPrivate *priv = raw->priv;
+
+ return priv->sockfd;
+}
diff --git a/camel/camel-tcp-stream-raw.h b/camel/camel-tcp-stream-raw.h
index ebf13fb..3b9698e 100644
--- a/camel/camel-tcp-stream-raw.h
+++ b/camel/camel-tcp-stream-raw.h
@@ -36,10 +36,7 @@ struct _CamelTcpStreamRaw
{
CamelTcpStream parent_object;
- gint sockfd;
-#ifdef G_OS_WIN32
- gint is_nonblocking;
-#endif
+ struct _CamelTcpStreamRawPrivate *priv;
};
typedef struct {
@@ -55,6 +52,8 @@ CamelType camel_tcp_stream_raw_get_type (void);
/* public methods */
CamelStream *camel_tcp_stream_raw_new (void);
+gint camel_tcp_stream_raw_get_fd (CamelTcpStreamRaw *raw);
+
G_END_DECLS
#endif /* CAMEL_TCP_STREAM_RAW_H */
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 7aedd0b..6b559cb 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -4280,7 +4280,7 @@ imapx_parser_thread (gpointer d)
GPollFD fds[2] = { {0, 0, 0}, {0, 0, 0} };
gint res;
- fds[0].fd = ((CamelTcpStreamRaw *)is->stream->source)->sockfd;
+ fds[0].fd = camel_tcp_stream_raw_get_fd ((CamelTcpStreamRaw *) is->stream->source);
fds[0].events = G_IO_IN;
fds[1].fd = camel_operation_cancel_fd (op);
fds[1].events = G_IO_IN;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]