Reorganize build system
[qemu/aliguori.git] / test-type-stub.c
blobb7019f281151539f8120cd6c80eacf9c2abf62fa
1 #include "qemu-common.h"
2 #include "qerror.h"
3 #include "qemu/type.h"
5 #include "test-type-stub.h"
6 #include "qemu_socket.h"
7 #include "qemu-char.h"
9 #include <glib.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)
28 int i;
30 type_system_init();
32 for (i = 0; i < num_modules_initfns; i++) {
33 module_initfns[i]();
37 #ifdef _WIN32
38 int send_all(int fd, const void *buf, int len1)
40 int ret, len;
42 len = len1;
43 while (len > 0) {
44 ret = send(fd, buf, len, 0);
45 if (ret < 0) {
46 errno = WSAGetLastError();
47 if (errno != WSAEWOULDBLOCK) {
48 return -1;
50 } else if (ret == 0) {
51 break;
52 } else {
53 buf += ret;
54 len -= ret;
57 return len1 - len;
60 #else
62 int send_all(int fd, const void *_buf, int len1)
64 int ret, len;
65 const uint8_t *buf = _buf;
67 len = len1;
68 while (len > 0) {
69 ret = write(fd, buf, len);
70 if (ret < 0) {
71 if (errno != EINTR && errno != EAGAIN)
72 return -1;
73 } else if (ret == 0) {
74 break;
75 } else {
76 buf += ret;
77 len -= ret;
80 return len1 - len;
82 #endif /* !_WIN32 */
84 #define MAX_FD 1024
86 typedef struct ChannelInfo
88 GIOChannel *channel;
89 guint tag;
90 IOHandler *io_read;
91 IOHandler *io_write;
92 void *opaque;
93 } 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);
109 return TRUE;
112 int qemu_set_fd_handler(int fd,
113 IOHandler *fd_read,
114 IOHandler *fd_write,
115 void *opaque)
117 GIOCondition cond = 0;
118 ChannelInfo *info = &io_channels[fd];
120 if (info->channel) {
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;
130 if (fd_read) {
131 cond |= G_IO_IN;
134 if (fd_write) {
135 cond |= G_IO_OUT;
138 info->tag = g_io_add_watch(info->channel, cond,
139 io_dispatcher, info);
141 return 0;