From db324b270e18f218039cf47ca736fe731147b2fb Mon Sep 17 00:00:00 2001 From: Alexander Tereshkin Date: Tue, 29 May 2012 17:07:17 +0400 Subject: [PATCH] libvchan_server_init() now does not wait for a client to connect. A server should wait for an incoming event and then call libvchan_server_handle_connected(). --- vchan/init.c | 18 +++++++++++------- vchan/io.c | 17 +++++++++++++++++ vchan/sources | 2 ++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/vchan/init.c b/vchan/init.c index 03227686..d870aea2 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -256,7 +256,7 @@ struct libvchan *libvchan_server_init(int devno) return ctrl; } -#ifndef WINNT + int libvchan_server_handle_connected(struct libvchan *ctrl) { @@ -264,14 +264,21 @@ int libvchan_server_handle_connected(struct libvchan *ctrl) char buf[64]; int ret = -1; int libvchan_fd; - fd_set rfds; +// fd_set rfds; +#ifdef WINNT + xs = xs_domain_open(); +#else xs = xs_daemon_open(); +#endif if (!xs) { return ret; } + +#ifndef WINNT // clear the pending flag xc_evtchn_pending(ctrl->evfd); +#endif snprintf(buf, sizeof buf, "device/vchan/%d", ctrl->devno); xs_rm(xs, 0, buf); @@ -291,6 +298,8 @@ fail2: return ret; } +#ifndef WINNT + /** retrieves ring-ref and event-channel numbers from xenstore (if they don't exist, return error, because nobody seems to listen); @@ -435,11 +444,6 @@ struct libvchan *libvchan_client_init(int domain, int devno) // Windows domains can not be dom0 -int libvchan_server_handle_connected(struct libvchan *ctrl) -{ - return -1; -} - struct libvchan *libvchan_client_init(int domain, int devno) { return NULL; diff --git a/vchan/io.c b/vchan/io.c index beed6caf..e735c86a 100644 --- a/vchan/io.c +++ b/vchan/io.c @@ -71,6 +71,22 @@ int libvchan_is_eof(struct libvchan *ctrl) /** \return -1 return value means peer has closed */ + +#ifdef WINNT +int libvchan_wait(struct libvchan *ctrl) +{ + int ret; + + ret = xc_evtchn_pending(ctrl->evfd); + if (ret!=-1 && xc_evtchn_unmask(ctrl->evfd, ctrl->evport)) + return -1; + if (ret!=-1 && libvchan_is_eof(ctrl)) + return -1; + return ret; +} + +#else + int libvchan_wait(struct libvchan *ctrl) { int ret; @@ -98,6 +114,7 @@ int libvchan_wait(struct libvchan *ctrl) return -1; return ret; } +#endif /** may sleep (only if no buffer space available); diff --git a/vchan/sources b/vchan/sources index 9b5e8eb8..1baae972 100644 --- a/vchan/sources +++ b/vchan/sources @@ -9,6 +9,8 @@ USE_MSVCRT=1 DLLDEF=libvchan.def +C_DEFINES = $(C_DEFINES) /DCONFIG_STUBDOM + INCLUDES=$(INCLUDES); \ ..\win\include;\