1 #include "qemu-common.h"
5 #include "test-type-stub.h"
6 #include "qemu_socket.h"
11 typedef void (module_initfn
)(void);
13 static int num_modules_initfns
;
14 static module_initfn
*module_initfns
[128];
16 void register_module_init(void (*fn
)(void), module_init_type type
)
18 module_initfns
[num_modules_initfns
++] = fn
;
21 QString
*qerror_format(const char *fmt
, QDict
*error
)
23 return qstring_from_str("");
26 void test_type_stub_init(void)
32 for (i
= 0; i
< num_modules_initfns
; i
++) {
38 int send_all(int fd
, const void *buf
, int len1
)
44 ret
= send(fd
, buf
, len
, 0);
46 errno
= WSAGetLastError();
47 if (errno
!= WSAEWOULDBLOCK
) {
50 } else if (ret
== 0) {
62 int send_all(int fd
, const void *_buf
, int len1
)
65 const uint8_t *buf
= _buf
;
69 ret
= write(fd
, buf
, len
);
71 if (errno
!= EINTR
&& errno
!= EAGAIN
)
73 } else if (ret
== 0) {
86 typedef struct ChannelInfo
95 static ChannelInfo io_channels
[MAX_FD
];
97 static gboolean
io_dispatcher(GIOChannel
*chan
, GIOCondition cond
, gpointer opaque
)
99 ChannelInfo
*info
= opaque
;
101 if ((cond
& G_IO_IN
)) {
102 info
->io_read(info
->opaque
);
105 if ((cond
& G_IO_OUT
)) {
106 info
->io_write(info
->opaque
);
112 int qemu_set_fd_handler(int fd
,
117 GIOCondition cond
= 0;
118 ChannelInfo
*info
= &io_channels
[fd
];
121 g_source_remove(info
->tag
);
122 g_io_channel_unref(info
->channel
);
125 info
->channel
= g_io_channel_unix_new(fd
);
126 info
->io_read
= fd_read
;
127 info
->io_write
= fd_write
;
128 info
->opaque
= opaque
;
138 info
->tag
= g_io_add_watch(info
->channel
, cond
,
139 io_dispatcher
, info
);