@@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#include "iohandler.h"
#include "qemu-common.h"
#include "net.h"
#include "monitor.h"
@@ -1909,7 +1910,7 @@ typedef struct {
int msgfd;
} TCPCharDriver;
-static void tcp_chr_accept(void *opaque);
+static int tcp_accept_handler(void *opaque, unsigned int mask);
static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
@@ -2064,9 +2065,10 @@ static void tcp_chr_read(void *opaque)
/* connection closed */
s->connected = 0;
if (s->listen_fd >= 0) {
- qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
+ assign_iohandler(s->listen_fd, tcp_accept_handler, IOH_MASK_READ,
+ chr);
}
- qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+ remove_iohandler(s->fd);
closesocket(s->fd);
s->fd = -1;
qemu_chr_event(chr, CHR_EVENT_CLOSED);
@@ -2078,6 +2080,22 @@ static void tcp_chr_read(void *opaque)
}
}
+static int tcp_iohandler(void *opaque, unsigned int mask)
+{
+ int ret;
+
+ ret = 0;
+ switch(mask) {
+ case IOH_MASK_CAN_READ:
+ ret = tcp_chr_read_poll(opaque);
+ break;
+ case IOH_MASK_READ:
+ tcp_chr_read(opaque);
+ break;
+ }
+ return ret;
+}
+
#ifndef _WIN32
CharDriverState *qemu_chr_open_eventfd(int eventfd)
{
@@ -2091,8 +2109,8 @@ static void tcp_chr_connect(void *opaque)
TCPCharDriver *s = chr->opaque;
s->connected = 1;
- qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
- tcp_chr_read, NULL, chr);
+ assign_iohandler(s->fd, tcp_iohandler, IOH_MASK_CAN_READ|IOH_MASK_READ,
+ chr);
qemu_chr_generic_open(chr);
}
@@ -2117,7 +2135,7 @@ static void socket_set_nodelay(int fd)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
}
-static void tcp_chr_accept(void *opaque)
+static int tcp_accept_handler(void *opaque, unsigned int mask)
{
CharDriverState *chr = opaque;
TCPCharDriver *s = chr->opaque;
@@ -2129,6 +2147,10 @@ static void tcp_chr_accept(void *opaque)
socklen_t len;
int fd;
+ if (!(mask & IOH_MASK_READ)) {
+ return 0;
+ }
+
for(;;) {
#ifndef _WIN32
if (s->is_unix) {
@@ -2142,7 +2164,7 @@ static void tcp_chr_accept(void *opaque)
}
fd = qemu_accept(s->listen_fd, addr, &len);
if (fd < 0 && errno != EINTR) {
- return;
+ return 0;
} else if (fd >= 0) {
if (s->do_telnetopt)
tcp_chr_telnet_init(fd);
@@ -2153,19 +2175,21 @@ static void tcp_chr_accept(void *opaque)
if (s->do_nodelay)
socket_set_nodelay(fd);
s->fd = fd;
- qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
+ remove_iohandler(s->listen_fd);
tcp_chr_connect(chr);
+
+ return 0;
}
static void tcp_chr_close(CharDriverState *chr)
{
TCPCharDriver *s = chr->opaque;
if (s->fd >= 0) {
- qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
+ remove_iohandler(s->fd);
closesocket(s->fd);
}
if (s->listen_fd >= 0) {
- qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
+ remove_iohandler(s->listen_fd);
closesocket(s->listen_fd);
}
qemu_free(s);
@@ -2227,7 +2251,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
if (is_listen) {
s->listen_fd = fd;
- qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
+ assign_iohandler(s->listen_fd, tcp_accept_handler, IOH_MASK_READ, chr);
if (is_telnet)
s->do_telnetopt = 1;
@@ -2257,7 +2281,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
if (is_listen && is_waitconnect) {
printf("QEMU waiting for connection on: %s\n",
chr->filename);
- tcp_chr_accept(chr);
+ tcp_accept_handler(chr, IOH_MASK_READ);
socket_set_nonblock(s->listen_fd);
}
return chr;
Update the tcp code to use the new iohandler api. The change is mostly mechanical with a new iohandler function calling the older functions depending on the value of the 'mask' field. Signed-off-by: Amit Shah <amit.shah@redhat.com> --- qemu-char.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 files changed, 36 insertions(+), 12 deletions(-)