| 1 | /*
|
|---|
| 2 | * linc-connection.h: This file is part of the linc library.
|
|---|
| 3 | *
|
|---|
| 4 | * Authors:
|
|---|
| 5 | * Elliot Lee (sopwith@redhat.com)
|
|---|
| 6 | * Michael Meeks (michael@ximian.com)
|
|---|
| 7 | * Mark McLouglin (mark@skynet.ie) & others
|
|---|
| 8 | *
|
|---|
| 9 | * Copyright 2001, Red Hat, Inc., Ximian, Inc.,
|
|---|
| 10 | * Sun Microsystems, Inc.
|
|---|
| 11 | */
|
|---|
| 12 | #ifndef _LINK_CONNECTION_H_
|
|---|
| 13 | #define _LINK_CONNECTION_H_
|
|---|
| 14 |
|
|---|
| 15 | #include <glib/gmacros.h>
|
|---|
| 16 |
|
|---|
| 17 | G_BEGIN_DECLS
|
|---|
| 18 |
|
|---|
| 19 | #ifdef G_OS_WIN32
|
|---|
| 20 | # include <winsock2.h>
|
|---|
| 21 | # undef interface /* #defined as struct! */
|
|---|
| 22 |
|
|---|
| 23 | # define iovec _WSABUF
|
|---|
| 24 | # define iov_len len
|
|---|
| 25 | # define iov_base buf
|
|---|
| 26 |
|
|---|
| 27 | #else
|
|---|
| 28 | # include <sys/uio.h>
|
|---|
| 29 | # include <netdb.h>
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #include <linc/linc-types.h>
|
|---|
| 33 | #include <linc/linc-protocol.h>
|
|---|
| 34 |
|
|---|
| 35 | #define LINK_TYPE_CONNECTION (link_connection_get_type())
|
|---|
| 36 | #define LINK_TYPE_IS_CONNECTION(type) (G_TYPE_FUNDAMENTAL (type) == LINK_TYPE_CONNECTION)
|
|---|
| 37 | #define LINK_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LINK_TYPE_CONNECTION, LinkConnection))
|
|---|
| 38 | #define LINK_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LINK_TYPE_CONNECTION, LinkConnectionClass))
|
|---|
| 39 | #define LINK_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LINK_TYPE_CONNECTION))
|
|---|
| 40 | #define LINK_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LINK_TYPE_CONNECTION))
|
|---|
| 41 |
|
|---|
| 42 | typedef enum { LINK_CONNECTING, LINK_CONNECTED, LINK_DISCONNECTED } LinkConnectionStatus;
|
|---|
| 43 |
|
|---|
| 44 | typedef struct _LinkWriteOpts LinkWriteOpts;
|
|---|
| 45 | typedef struct _LinkConnectionPrivate LinkConnectionPrivate;
|
|---|
| 46 |
|
|---|
| 47 | typedef struct {
|
|---|
| 48 | GObject parent;
|
|---|
| 49 |
|
|---|
| 50 | const LinkProtocolInfo *proto;
|
|---|
| 51 |
|
|---|
| 52 | LinkConnectionStatus status;
|
|---|
| 53 | LinkConnectionOptions options;
|
|---|
| 54 | guint was_initiated : 1;
|
|---|
| 55 | guint is_auth : 1;
|
|---|
| 56 | guint inhibit_reconnect : 1;
|
|---|
| 57 |
|
|---|
| 58 | gchar *remote_host_info;
|
|---|
| 59 | gchar *remote_serv_info;
|
|---|
| 60 |
|
|---|
| 61 | LinkConnectionPrivate *priv;
|
|---|
| 62 |
|
|---|
| 63 | GSList *idle_broken_callbacks;
|
|---|
| 64 | } LinkConnection;
|
|---|
| 65 |
|
|---|
| 66 | typedef struct {
|
|---|
| 67 | GObjectClass parent_class;
|
|---|
| 68 |
|
|---|
| 69 | void (* state_changed) (LinkConnection *cnx,
|
|---|
| 70 | LinkConnectionStatus status);
|
|---|
| 71 | gboolean (* handle_input) (LinkConnection *cnx);
|
|---|
| 72 |
|
|---|
| 73 | /* signals */
|
|---|
| 74 | void (* broken) (LinkConnection *cnx);
|
|---|
| 75 | /*
|
|---|
| 76 | * Emitted when the buffer is emptied, half full or
|
|---|
| 77 | * before disconnect
|
|---|
| 78 | */
|
|---|
| 79 | void (* blocking) (LinkConnection *cnx,
|
|---|
| 80 | gulong buffer_size);
|
|---|
| 81 | } LinkConnectionClass;
|
|---|
| 82 |
|
|---|
| 83 | GType link_connection_get_type (void) G_GNUC_CONST;
|
|---|
| 84 |
|
|---|
| 85 | void link_connection_from_fd (LinkConnection *cnx,
|
|---|
| 86 | int fd,
|
|---|
| 87 | const LinkProtocolInfo *proto,
|
|---|
| 88 | gchar *remote_host_info,
|
|---|
| 89 | gchar *remote_serv_info,
|
|---|
| 90 | gboolean was_initiated,
|
|---|
| 91 | LinkConnectionStatus status,
|
|---|
| 92 | LinkConnectionOptions options);
|
|---|
| 93 |
|
|---|
| 94 | LinkConnection *link_connection_initiate (GType derived_type,
|
|---|
| 95 | const char *proto_name,
|
|---|
| 96 | const char *remote_host_info,
|
|---|
| 97 | const char *remote_serv_info,
|
|---|
| 98 | LinkConnectionOptions options,
|
|---|
| 99 | const char *first_property,
|
|---|
| 100 | ...);
|
|---|
| 101 | LinkConnectionStatus link_connection_try_reconnect (LinkConnection *cnx);
|
|---|
| 102 |
|
|---|
| 103 | gpointer link_connection_ref (gpointer cnx);
|
|---|
| 104 | void link_connection_unref (gpointer cnx);
|
|---|
| 105 |
|
|---|
| 106 | typedef enum {
|
|---|
| 107 | LINK_IO_OK = 0,
|
|---|
| 108 | LINK_IO_FATAL_ERROR = -1,
|
|---|
| 109 | LINK_IO_QUEUED_DATA = -2
|
|---|
| 110 | } LinkIOStatus;
|
|---|
| 111 |
|
|---|
| 112 | glong link_connection_read (LinkConnection *cnx,
|
|---|
| 113 | guchar *buf,
|
|---|
| 114 | int len,
|
|---|
| 115 | gboolean block_for_full_read);
|
|---|
| 116 |
|
|---|
| 117 | /* Return values from these functions are going to be "abnormal",
|
|---|
| 118 | since they make sure to write all the data out */
|
|---|
| 119 | LinkIOStatus link_connection_write (LinkConnection *cnx,
|
|---|
| 120 | const guchar *buf,
|
|---|
| 121 | gulong len,
|
|---|
| 122 | const LinkWriteOpts *opt_write_opts);
|
|---|
| 123 |
|
|---|
| 124 | LinkIOStatus link_connection_writev (LinkConnection *cnx,
|
|---|
| 125 | struct iovec *vecs,
|
|---|
| 126 | int nvecs,
|
|---|
| 127 | const LinkWriteOpts *opt_write_opts);
|
|---|
| 128 |
|
|---|
| 129 | void link_connection_state_changed (LinkConnection *cnx,
|
|---|
| 130 | LinkConnectionStatus status);
|
|---|
| 131 |
|
|---|
| 132 | LinkConnectionStatus link_connection_get_status (LinkConnection *cnx);
|
|---|
| 133 | void link_connection_disconnect (LinkConnection *cnx);
|
|---|
| 134 | LinkConnectionStatus link_connection_wait_connected (LinkConnection *cnx);
|
|---|
| 135 |
|
|---|
| 136 | /*
|
|---|
| 137 | * Proposed new blocking API ...
|
|---|
| 138 | */
|
|---|
| 139 | void link_connection_set_max_buffer (LinkConnection *cnx,
|
|---|
| 140 | gulong max_buffer_bytes);
|
|---|
| 141 | LinkWriteOpts *link_write_options_new (gboolean block_on_write);
|
|---|
| 142 | /* Space for future expansion: timeout, individual msg. buffering constraints etc. */
|
|---|
| 143 | void link_write_options_free (LinkWriteOpts *write_opts);
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 | typedef void (*LinkBrokenCallback) (LinkConnection *, gpointer user_data);
|
|---|
| 147 | void link_connection_add_broken_cb (LinkConnection *cnx,
|
|---|
| 148 | LinkBrokenCallback fn,
|
|---|
| 149 | gpointer user_data);
|
|---|
| 150 | void link_connection_remove_broken_cb (LinkConnection *cnx,
|
|---|
| 151 | LinkBrokenCallback opt_fn,
|
|---|
| 152 | gpointer opt_user_data);
|
|---|
| 153 |
|
|---|
| 154 | void link_connections_close (void);
|
|---|
| 155 |
|
|---|
| 156 | G_END_DECLS
|
|---|
| 157 |
|
|---|
| 158 | #endif /* _LINK_CONNECTION_H */
|
|---|