1 #ifndef __GSK_STREAM_FD_H_ 2 #define __GSK_STREAM_FD_H_ 3 4 #include "gskstream.h" 5 #include "gsksocketaddresssymbolic.h" 6 7 G_BEGIN_DECLS 8 9 /* --- typedefs --- */ 10 typedef struct _GskStreamFd GskStreamFd; 11 typedef struct _GskStreamFdClass GskStreamFdClass; 12 13 /* --- type macros --- */ 14 GType gsk_stream_fd_get_type(void) G_GNUC_CONST; 15 #define GSK_TYPE_STREAM_FD (gsk_stream_fd_get_type ()) 16 #define GSK_STREAM_FD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSK_TYPE_STREAM_FD, GskStreamFd)) 17 #define GSK_STREAM_FD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSK_TYPE_STREAM_FD, GskStreamFdClass)) 18 #define GSK_STREAM_FD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSK_TYPE_STREAM_FD, GskStreamFdClass)) 19 #define GSK_IS_STREAM_FD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSK_TYPE_STREAM_FD)) 20 #define GSK_IS_STREAM_FD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSK_TYPE_STREAM_FD)) 21 22 #define GSK_STREAM_FD_GET_FD(stream) (GSK_STREAM_FD (stream)->fd) 23 24 #define GSK_STREAM_FD_USE_GLIB_MAIN_LOOP 0 25 26 #if !GSK_STREAM_FD_USE_GLIB_MAIN_LOOP 27 #include "gskmainloop.h" 28 #endif 29 30 /* --- structures --- */ 31 struct _GskStreamFdClass 32 { 33 GskStreamClass stream_class; 34 }; 35 struct _GskStreamFd 36 { 37 GskStream stream; 38 39 /* read-only */ 40 guint is_pollable : 1; 41 guint is_shutdownable : 1; 42 guint is_resolving_name : 1; 43 guint failed_name_resolution : 1; 44 45 int fd; 46 gushort post_connecting_events; 47 #if GSK_STREAM_FD_USE_GLIB_MAIN_LOOP 48 GPollFD poll_fd; 49 GSource *source; 50 #else 51 GskSource *source; 52 #endif 53 }; 54 55 /* --- prototypes --- */ 56 typedef enum 57 { 58 GSK_STREAM_FD_IS_READABLE = (1<<0), 59 GSK_STREAM_FD_IS_WRITABLE = (1<<1), 60 GSK_STREAM_FD_IS_READWRITE = GSK_STREAM_FD_IS_READABLE 61 | GSK_STREAM_FD_IS_WRITABLE, 62 GSK_STREAM_FD_IS_POLLABLE = (1<<2), 63 GSK_STREAM_FD_IS_SHUTDOWNABLE = (1<<3), 64 GSK_STREAM_FD_FOR_NEW_SOCKET = GSK_STREAM_FD_IS_READWRITE 65 | GSK_STREAM_FD_IS_POLLABLE 66 | GSK_STREAM_FD_IS_SHUTDOWNABLE 67 } GskStreamFdFlags; 68 69 GskStream *gsk_stream_fd_new (gint fd, 70 GskStreamFdFlags flags); 71 GskStreamFdFlags gsk_stream_fd_flags_guess (gint fd); 72 GskStream *gsk_stream_fd_new_auto (gint fd); 73 74 75 GskStream *gsk_stream_fd_new_connecting (gint fd); 76 GskStream *gsk_stream_fd_new_from_symbolic_address (GskSocketAddressSymbolic *symbolic, 77 GError **error); 78 79 /* reading/writing from/to a file */ 80 GskStream *gsk_stream_fd_new_read_file (const char *filename, 81 GError **error); 82 GskStream *gsk_stream_fd_new_write_file (const char *filename, 83 gboolean may_create, 84 gboolean should_truncate, 85 GError **error); 86 GskStream *gsk_stream_fd_new_create_file (const char *filename, 87 gboolean may_exist, 88 GError **error); 89 90 91 /*< private >*/ 92 GskStream * gsk_stream_fd_new_open (const char *filename, 93 guint open_flags, 94 guint permission, 95 GError **error); 96 97 gboolean gsk_stream_fd_pipe (GskStream **read_side_out, 98 GskStream **write_side_out, 99 GError **error); 100 101 gboolean gsk_stream_fd_duplex_pipe (GskStream **side_a_out, 102 GskStream **side_b_out, 103 GError **error); 104 gboolean gsk_stream_fd_duplex_pipe_fd (GskStream **side_a_out, 105 int *side_b_fd_out, 106 GError **error); 107 108 G_END_DECLS 109 110 #endif 111