diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2012-08-09 15:09:19 +0100 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2012-08-20 13:34:34 +0100 |
commit | 5435f17ed66ea4ec48b9c187bbf6296954c61c0b (patch) | |
tree | 1926e95b7973a40f034efa3295f6f86366a4a1d5 /src/rpc/virnetserverservice.c | |
parent | Refactor impl of the virNetServerClientNew method (diff) | |
download | libvirt-5435f17ed66ea4ec48b9c187bbf6296954c61c0b.tar.gz libvirt-5435f17ed66ea4ec48b9c187bbf6296954c61c0b.tar.bz2 libvirt-5435f17ed66ea4ec48b9c187bbf6296954c61c0b.zip |
Add support for creating sockets & RPC servers from a pre-opened fd
In order to support systemd socket based activation, it needs to
be possible to create virNetSocketPtr and virNetServerServicePtr
instance from a pre-opened file descriptor
Diffstat (limited to 'src/rpc/virnetserverservice.c')
-rw-r--r-- | src/rpc/virnetserverservice.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index eda5ef91c..53ff50310 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -200,6 +200,55 @@ error: return NULL; } +virNetServerServicePtr virNetServerServiceNewFD(int fd, + int auth, + bool readonly, + size_t nrequests_client_max, + virNetTLSContextPtr tls) +{ + virNetServerServicePtr svc; + int i; + + if (virNetServerServiceInitialize() < 0) + return NULL; + + if (!(svc = virObjectNew(virNetServerServiceClass))) + return NULL; + + svc->auth = auth; + svc->readonly = readonly; + svc->nrequests_client_max = nrequests_client_max; + svc->tls = virObjectRef(tls); + + svc->nsocks = 1; + if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0) + goto no_memory; + + if (virNetSocketNewListenFD(fd, + &svc->socks[0]) < 0) + goto error; + + for (i = 0 ; i < svc->nsocks ; i++) { + /* IO callback is initially disabled, until we're ready + * to deal with incoming clients */ + if (virNetSocketAddIOCallback(svc->socks[i], + 0, + virNetServerServiceAccept, + svc, + virObjectFreeCallback) < 0) + goto error; + } + + + return svc; + +no_memory: + virReportOOMError(); +error: + virObjectUnref(svc); + return NULL; +} + int virNetServerServiceGetPort(virNetServerServicePtr svc) { |