source: trunk/ORBit2-2.14.0/linc2/include/linc/linc-connection.h

Last change on this file was 92, checked in by cinc, 19 years ago

Orbit2 modified for use with NOM

File size: 5.2 KB
Line 
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
17G_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
42typedef enum { LINK_CONNECTING, LINK_CONNECTED, LINK_DISCONNECTED } LinkConnectionStatus;
43
44typedef struct _LinkWriteOpts LinkWriteOpts;
45typedef struct _LinkConnectionPrivate LinkConnectionPrivate;
46
47typedef 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
66typedef 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
83GType link_connection_get_type (void) G_GNUC_CONST;
84
85void 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
94LinkConnection *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 ...);
101LinkConnectionStatus link_connection_try_reconnect (LinkConnection *cnx);
102
103gpointer link_connection_ref (gpointer cnx);
104void link_connection_unref (gpointer cnx);
105
106typedef enum {
107 LINK_IO_OK = 0,
108 LINK_IO_FATAL_ERROR = -1,
109 LINK_IO_QUEUED_DATA = -2
110} LinkIOStatus;
111
112glong 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 */
119LinkIOStatus link_connection_write (LinkConnection *cnx,
120 const guchar *buf,
121 gulong len,
122 const LinkWriteOpts *opt_write_opts);
123
124LinkIOStatus link_connection_writev (LinkConnection *cnx,
125 struct iovec *vecs,
126 int nvecs,
127 const LinkWriteOpts *opt_write_opts);
128
129void link_connection_state_changed (LinkConnection *cnx,
130 LinkConnectionStatus status);
131
132LinkConnectionStatus link_connection_get_status (LinkConnection *cnx);
133void link_connection_disconnect (LinkConnection *cnx);
134LinkConnectionStatus link_connection_wait_connected (LinkConnection *cnx);
135
136/*
137 * Proposed new blocking API ...
138 */
139void link_connection_set_max_buffer (LinkConnection *cnx,
140 gulong max_buffer_bytes);
141LinkWriteOpts *link_write_options_new (gboolean block_on_write);
142/* Space for future expansion: timeout, individual msg. buffering constraints etc. */
143void link_write_options_free (LinkWriteOpts *write_opts);
144
145
146typedef void (*LinkBrokenCallback) (LinkConnection *, gpointer user_data);
147void link_connection_add_broken_cb (LinkConnection *cnx,
148 LinkBrokenCallback fn,
149 gpointer user_data);
150void link_connection_remove_broken_cb (LinkConnection *cnx,
151 LinkBrokenCallback opt_fn,
152 gpointer opt_user_data);
153
154void link_connections_close (void);
155
156G_END_DECLS
157
158#endif /* _LINK_CONNECTION_H */
Note: See TracBrowser for help on using the repository browser.