[glibmm] add start of Socket class
- From: Jonathon Jongsma <jjongsma src gnome org>
- To: svn-commits-list gnome org
- Subject: [glibmm] add start of Socket class
- Date: Sat, 20 Jun 2009 01:10:03 -0400 (EDT)
commit e963653133436d04cc4b45a312200cc795aa824f
Author: Jonathon Jongsma <jonathon quotidian org>
Date: Sat Jun 20 00:08:19 2009 -0500
add start of Socket class
ChangeLog | 13 +++
gio/src/Makefile_list_of_hg.am_fragment | 1 +
gio/src/gio_enums.defs | 32 ++++++
gio/src/gio_signals.defs | 83 ++++++++++++++++
gio/src/socket.ccg | 26 +++++
gio/src/socket.hg | 150 +++++++++++++++++++++++++++++
tools/extra_defs_gen/generate_defs_gio.cc | 1 +
tools/m4/convert_gio.m4 | 9 ++
8 files changed, 315 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0edc420..535ac5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2009-06-19 Jonathon Jongsma <jonathon quotidian org>
+ Add start of Socket class
+
+ * gio/src/Makefile_list_of_hg.am_fragment:
+ * gio/src/gio_enums.defs:
+ * gio/src/gio_signals.defs:
+ * gio/src/socket.ccg: Added.
+ * gio/src/socket.hg: Added.
+ * tools/enum.pl:
+ * tools/extra_defs_gen/generate_defs_gio.cc:
+ * tools/m4/convert_gio.m4:
+
+2009-06-19 Jonathon Jongsma <jonathon quotidian org>
+
Add start of Initable
This class may require a bit of additional thought since it implies
that we will need to call a special g_initable_new() constructor
diff --git a/gio/src/Makefile_list_of_hg.am_fragment b/gio/src/Makefile_list_of_hg.am_fragment
index a55792c..da4ef1b 100644
--- a/gio/src/Makefile_list_of_hg.am_fragment
+++ b/gio/src/Makefile_list_of_hg.am_fragment
@@ -47,6 +47,7 @@ files_general_hg = \
outputstream.hg \
resolver.hg \
seekable.hg \
+ socket.hg \
socketaddressenumerator.hg \
socketaddress.hg \
socketconnectable.hg \
diff --git a/gio/src/gio_enums.defs b/gio/src/gio_enums.defs
index 530231d..4c42806 100644
--- a/gio/src/gio_enums.defs
+++ b/gio/src/gio_enums.defs
@@ -103,6 +103,26 @@
)
)
+(define-enum-extended DriveStartFlags
+ (in-module "G")
+ (c-name "GDriveStartFlags")
+ (values
+ '("e" "G_DRIVE_START_NONE" "0")
+ )
+)
+
+(define-enum-extended DriveStartStopType
+ (in-module "G")
+ (c-name "GDriveStartStopType")
+ (values
+ '("unknown" "G_DRIVE_START_STOP_TYPE_UNKNOWN" "0")
+ '("shutdown" "G_DRIVE_START_STOP_TYPE_SHUTDOWN" "1")
+ '("network" "G_DRIVE_START_STOP_TYPE_NETWORK" "2")
+ '("multidisk" "G_DRIVE_START_STOP_TYPE_MULTIDISK" "3")
+ '("password" "G_DRIVE_START_STOP_TYPE_PASSWORD" "4")
+ )
+)
+
(define-flags-extended FileCopyFlags
(in-module "G")
(c-name "GFileCopyFlags")
@@ -300,3 +320,15 @@
)
)
+(define-enum-extended SocketProtocol
+ (in-module "G")
+ (c-name "GSocketProtocol")
+ (values
+ '("unknown" "G_SOCKET_PROTOCOL_UNKNOWN" "-1")
+ '("default" "G_SOCKET_PROTOCOL_DEFAULT" "0")
+ '("tcp" "G_SOCKET_PROTOCOL_TCP" "6")
+ '("udp" "G_SOCKET_PROTOCOL_UDP" "17")
+ '("sctp" "G_SOCKET_PROTOCOL_SCTP" "132")
+ )
+)
+
diff --git a/gio/src/gio_signals.defs b/gio/src/gio_signals.defs
index 549e5e0..a36f6c8 100644
--- a/gio/src/gio_signals.defs
+++ b/gio/src/gio_signals.defs
@@ -815,4 +815,87 @@
(construct-only #t)
)
+;; From GSocket
+
+(define-property family
+ (of-object "GSocket")
+ (prop-type "GParamEnum")
+ (docs "The sockets address family")
+ (readable #t)
+ (writable #t)
+ (construct-only #t)
+)
+
+(define-property type
+ (of-object "GSocket")
+ (prop-type "GParamEnum")
+ (docs "The sockets type")
+ (readable #t)
+ (writable #t)
+ (construct-only #t)
+)
+
+(define-property protocol
+ (of-object "GSocket")
+ (prop-type "GParamEnum")
+ (docs "The id of the protocol to use, or -1 for unknown")
+ (readable #t)
+ (writable #t)
+ (construct-only #t)
+)
+
+(define-property fd
+ (of-object "GSocket")
+ (prop-type "GParamInt")
+ (docs "The sockets file descriptor")
+ (readable #t)
+ (writable #t)
+ (construct-only #t)
+)
+
+(define-property blocking
+ (of-object "GSocket")
+ (prop-type "GParamBoolean")
+ (docs "Whether or not I/O on this socket is blocking")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+)
+
+(define-property listen-backlog
+ (of-object "GSocket")
+ (prop-type "GParamInt")
+ (docs "Outstanding connections in the listen queue")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+)
+
+(define-property keepalive
+ (of-object "GSocket")
+ (prop-type "GParamBoolean")
+ (docs "Keep connection alive by sending periodic pings")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+)
+
+(define-property local-address
+ (of-object "GSocket")
+ (prop-type "GParamObject")
+ (docs "The local address the socket is bound to")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+)
+
+(define-property remote-address
+ (of-object "GSocket")
+ (prop-type "GParamObject")
+ (docs "The remote address the socket is connected to")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+)
+
diff --git a/gio/src/socket.ccg b/gio/src/socket.ccg
new file mode 100644
index 0000000..251999b
--- /dev/null
+++ b/gio/src/socket.ccg
@@ -0,0 +1,26 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2007 The giomm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+#include <giomm/asyncresult.h>
+#include "slot_async.h"
+
+namespace Gio
+{
+} // namespace Gio
diff --git a/gio/src/socket.hg b/gio/src/socket.hg
new file mode 100644
index 0000000..d6055ba
--- /dev/null
+++ b/gio/src/socket.hg
@@ -0,0 +1,150 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2009 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/object.h>
+#include <giomm/initable.h>
+#include <giomm/socketconnectable.h>
+#include <giomm/socketaddress.h>
+#include <giomm/enums.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gio
+{
+
+_WRAP_ENUM(SocketType, GSocketType)
+_WRAP_ENUM(SocketProtocol, GSocketProtocol)
+_WRAP_ENUM(SocketMsgFlags, GSocketMsgFlags)
+
+/** Low-level socket object
+ *
+ * A Socket is a low-level networking primitive. It is a more or less direct
+ * mapping of the BSD socket API in a portable GObject based API. It supports
+ * both the UNIX socket implementations and winsock2 on Windows.
+ *
+ * Socket is the platform independent base upon which the higher level network
+ * primitives are based. Applications are not typically meant to use it
+ * directly, but rather through classes like SocketClient, SocketService and
+ * SocketConnection. However there may be cases where direct use of Socket is
+ * useful.
+ *
+ * (FIXME: update this doc for giomm)
+ * Socket implements the Initable interface, so if it is manually constructed by
+ * e.g. g_object_new() you must call g_initable_init() and check the results
+ * before using the object. This is done automatically in g_socket_new() and
+ * g_socket_new_from_fd(), so these functions can return NULL.
+ *
+ * Sockets operate in two general modes, blocking or non-blocking. When in
+ * blocking mode all operations block until the requested operation is finished
+ * or there is an error. In non-blocking mode all calls that would block return
+ * immediately with a G_IO_ERROR_WOULD_BLOCK error. To know when a call would
+ * successfully run you can call condition_check(), or condition_wait(). You can
+ * also use create_source() and attach it to a Glib::MainContext to get
+ * callbacks when I/O is possible. Note that all sockets are always set to non
+ * blocking mode in the system, and blocking mode is emulated in Socket.
+ *
+ * When working in non-blocking mode applications should always be able to
+ * handle getting a G_IO_ERROR_WOULD_BLOCK error even when some other function
+ * said that I/O was possible. This can easily happen in case of a race
+ * condition in the application, but it can also happen for other reasons. For
+ * instance, on Windows a socket is always seen as writable until a write
+ * returns G_IO_ERROR_WOULD_BLOCK.
+ *
+ * Sockets can be either connection oriented or datagram based. For connection
+ * oriented types you must first establish a connection by either connecting to
+ * an address or accepting a connection from another address. For connectionless
+ * socket types the target/source address is specified or received in each I/O
+ * operation.
+ *
+ * All socket file descriptors are set to be close-on-exec.
+ *
+ * Note that creating a Socket causes the signal SIGPIPE to be ignored for the
+ * remainder of the program. If you are writing a command-line utility that uses
+ * Socket, you may need to take into account the fact that your program will not
+ * automatically be killed if it tries to write to stdout after it has been
+ * closed.
+ *
+ * @newin2p22
+ */
+class Socket : public Glib::Object,
+ public Initable
+{
+ _CLASS_GOBJECT(Socket, GSocket, G_SOCKET, Glib::Object, GObject)
+ _IMPLEMENTS_INTERFACE(Initable)
+
+ // FIXME: figure out initable constructors
+
+public:
+
+ _WRAP_METHOD(void bind(const Glib::RefPtr<SocketAddress>& address, bool allow_reuse), g_socket_bind, errthrow)
+ _WRAP_METHOD(void listen(), g_socket_listen, errthrow)
+ _WRAP_METHOD(Glib::RefPtr<Socket> accept(), g_socket_accept, errthrow)
+ _WRAP_METHOD(void connect(const Glib::RefPtr<SocketAddress>& address), g_socket_connect, errthrow)
+ // FIXME: it doesn't really seem like this is a proper use of exceptions...
+ _WRAP_METHOD(void check_connect_result(), g_socket_check_connect_result, errthrow)
+ // TODO: std::string overload?
+ _WRAP_METHOD(gssize receive(char* buffer, gsize size), g_socket_receive, errthrow)
+ // TODO: std::string overload?
+ // TODO: need to do manually?
+ //_WRAP_METHOD(gssize receive_from(Glib::RefPtr<SocketAddress>& address, char* buffer, gsize size), g_socket_receive_from, errthrow)
+ // TODO: wrap receive_message -- figure out this GInputVector thing
+ // TODO: std::string overload?
+ _WRAP_METHOD(gssize send(const gchar* buffer, gsize size), g_socket_send, errthrow)
+ // TODO: std::string overload?
+ _WRAP_METHOD(gssize send_to(const Glib::RefPtr<SocketAddress>& address, const char* buffer, gsize size), g_socket_send_to, errthrow)
+ // TODO: wrap send_message -- figure out this GOutputVector thing
+ _WRAP_METHOD(void close(), g_socket_close, errthrow)
+ _WRAP_METHOD(bool is_closed(), g_socket_is_closed)
+ _WRAP_METHOD(void shutdown(bool shutdown_read, bool shutdown_write), g_socket_shutdown, errthrow)
+ _WRAP_METHOD(bool is_connected(), g_socket_is_connected)
+ // TODO: non-cancellable version
+ // This won't work because Glib::Source is abstract, and Glib::IOSource has no
+ // constructor that takes a GSource*
+//#m4 _CONVERSION(`GSource*',`Glib::RefPtr<Glib::Source>',`Glib::RefPtr<Glib::Source>(new ::Glib::Source($3))')
+ //_WRAP_METHOD(Glib::RefPtr<Glib::Source> create_source(Glib::IOCondition condition, const Glib::RefPtr<Cancellable>& cancellable), g_socket_create_source)
+ _WRAP_METHOD(Glib::IOCondition condition_check(Glib::IOCondition condition), g_socket_condition_check)
+ // TODO: non-cancellable version
+ _WRAP_METHOD(void condition_wait(Glib::IOCondition condition, const Glib::RefPtr<Cancellable>& cancellable), g_socket_condition_wait, errthrow)
+ _WRAP_METHOD(void set_listen_backlog(int backlog), g_socket_set_listen_backlog)
+ _WRAP_METHOD(int get_listen_backlog() const, g_socket_get_listen_backlog)
+ _WRAP_METHOD(void set_blocking(bool blocking), g_socket_set_blocking)
+ _WRAP_METHOD(bool get_blocking() const, g_socket_get_blocking)
+ _WRAP_METHOD(void set_keepalive(bool keepalive), g_socket_set_keepalive)
+ _WRAP_METHOD(bool get_keepalive() const, g_socket_get_keepalive)
+ _WRAP_METHOD(SocketFamily get_family() const, g_socket_get_family)
+ _WRAP_METHOD(int get_fd() const, g_socket_get_fd)
+ _WRAP_METHOD(Glib::RefPtr<SocketAddress> get_local_address() const, g_socket_get_local_address, errthrow)
+ _WRAP_METHOD(Glib::RefPtr<SocketAddress> get_remote_address() const, g_socket_get_remote_address, errthrow)
+ _WRAP_METHOD(SocketProtocol get_protocol() const, g_socket_get_protocol)
+ _WRAP_METHOD(SocketType get_socket_type() const, g_socket_get_socket_type)
+ _WRAP_METHOD(bool speaks_ipv4() const, g_socket_speaks_ipv4)
+
+ _WRAP_PROPERTY("blocking", bool)
+ _WRAP_PROPERTY("family", SocketFamily)
+ _WRAP_PROPERTY("fd", int)
+ _WRAP_PROPERTY("keepalive", bool)
+ _WRAP_PROPERTY("listen-backlog", int)
+ _WRAP_PROPERTY("local-address", Glib::RefPtr<SocketAddress>)
+ _WRAP_PROPERTY("remote-address", Glib::RefPtr<SocketAddress>)
+ _WRAP_PROPERTY("protocol", SocketProtocol)
+ _WRAP_PROPERTY("type", SocketType)
+};
+
+} // namespace Gio
diff --git a/tools/enum.pl b/tools/enum.pl
old mode 100644
new mode 100755
diff --git a/tools/extra_defs_gen/generate_defs_gio.cc b/tools/extra_defs_gen/generate_defs_gio.cc
index 5b9481e..90b4388 100644
--- a/tools/extra_defs_gen/generate_defs_gio.cc
+++ b/tools/extra_defs_gen/generate_defs_gio.cc
@@ -81,6 +81,7 @@ int main (int argc, char** argv)
<< get_defs(G_TYPE_RESOLVER)
<< get_defs(G_TYPE_NETWORK_ADDRESS)
<< get_defs(G_TYPE_NETWORK_SERVICE)
+ << get_defs(G_TYPE_SOCKET)
<< std::endl;
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index ab0bdc4..5a60ede 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -17,6 +17,9 @@ _CONV_ENUM(G,DataStreamByteOrder)
_CONV_ENUM(G,DataStreamNewlineType)
_CONV_ENUM(G,EmblemOrigin)
_CONV_ENUM(G,SocketFamily)
+_CONV_ENUM(G,SocketType)
+_CONV_ENUM(G,SocketProtocol)
+_CONV_ENUM(G,SocketMsgFlags)
# AppInfo
@@ -113,8 +116,14 @@ _CONVERSION(`PasswordSave',`GPasswordSave',`($2)$3')
_CONVERSION(`GOutputStream*',`Glib::RefPtr<OutputStream>',`Glib::wrap($3)')
_CONVERSION(`const Glib::RefPtr<OutputStream>&',`GOutputStream*',__CONVERT_CONST_REFPTR_TO_P)
+#Socket
+_CONVERSION(`const Glib::RefPtr<Socket>&',`GSocket*',__CONVERT_CONST_REFPTR_TO_P)
+_CONVERSION(`GSocket*',`Glib::RefPtr<Socket>',`Glib::wrap($3)')
+
#SocketAddress
_CONVERSION(`GSocketAddress*',`Glib::RefPtr<SocketAddress>',`Glib::wrap($3)')
+_CONVERSION(`const Glib::RefPtr<SocketAddress>&',`GSocketAddress*',__CONVERT_CONST_REFPTR_TO_P)
+_CONVERSION(`Glib::RefPtr<SocketAddress>&',`GSocketAddress*',__CONVERT_CONST_REFPTR_TO_P)
_CONVERSION(`GSocketAddressEnumerator*',`Glib::RefPtr<SocketAddressEnumerator>',`Glib::wrap($3)')
#Volume
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]