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().

This commit is contained in:
Alexander Tereshkin 2012-05-29 17:07:17 +04:00
parent e31128341b
commit db324b270e
3 changed files with 30 additions and 7 deletions

View File

@ -256,7 +256,7 @@ struct libvchan *libvchan_server_init(int devno)
return ctrl; return ctrl;
} }
#ifndef WINNT
int libvchan_server_handle_connected(struct libvchan *ctrl) int libvchan_server_handle_connected(struct libvchan *ctrl)
{ {
@ -264,14 +264,21 @@ int libvchan_server_handle_connected(struct libvchan *ctrl)
char buf[64]; char buf[64];
int ret = -1; int ret = -1;
int libvchan_fd; int libvchan_fd;
fd_set rfds; // fd_set rfds;
#ifdef WINNT
xs = xs_domain_open();
#else
xs = xs_daemon_open(); xs = xs_daemon_open();
#endif
if (!xs) { if (!xs) {
return ret; return ret;
} }
#ifndef WINNT
// clear the pending flag // clear the pending flag
xc_evtchn_pending(ctrl->evfd); xc_evtchn_pending(ctrl->evfd);
#endif
snprintf(buf, sizeof buf, "device/vchan/%d", ctrl->devno); snprintf(buf, sizeof buf, "device/vchan/%d", ctrl->devno);
xs_rm(xs, 0, buf); xs_rm(xs, 0, buf);
@ -291,6 +298,8 @@ fail2:
return ret; return ret;
} }
#ifndef WINNT
/** /**
retrieves ring-ref and event-channel numbers from xenstore (if retrieves ring-ref and event-channel numbers from xenstore (if
they don't exist, return error, because nobody seems to listen); 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 // 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) struct libvchan *libvchan_client_init(int domain, int devno)
{ {
return NULL; return NULL;

View File

@ -71,6 +71,22 @@ int libvchan_is_eof(struct libvchan *ctrl)
/** /**
\return -1 return value means peer has closed \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 libvchan_wait(struct libvchan *ctrl)
{ {
int ret; int ret;
@ -98,6 +114,7 @@ int libvchan_wait(struct libvchan *ctrl)
return -1; return -1;
return ret; return ret;
} }
#endif
/** /**
may sleep (only if no buffer space available); may sleep (only if no buffer space available);

View File

@ -9,6 +9,8 @@ USE_MSVCRT=1
DLLDEF=libvchan.def DLLDEF=libvchan.def
C_DEFINES = $(C_DEFINES) /DCONFIG_STUBDOM
INCLUDES=$(INCLUDES); \ INCLUDES=$(INCLUDES); \
..\win\include;\ ..\win\include;\