virnetsocket.h 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * virnetsocket.h: generic network socket handling
 *
 * Copyright (C) 2006-2011 Red Hat, Inc.
 * Copyright (C) 2006 Daniel P. Berrange
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __VIR_NET_SOCKET_H__
# define __VIR_NET_SOCKET_H__

27
# include "virsocketaddr.h"
28
# include "command.h"
29 30 31 32
# include "virnettlscontext.h"
# ifdef HAVE_SASL
#  include "virnetsaslcontext.h"
# endif
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

typedef struct _virNetSocket virNetSocket;
typedef virNetSocket *virNetSocketPtr;


typedef void (*virNetSocketIOFunc)(virNetSocketPtr sock,
                                   int events,
                                   void *opaque);


int virNetSocketNewListenTCP(const char *nodename,
                             const char *service,
                             virNetSocketPtr **addrs,
                             size_t *naddrs);

int virNetSocketNewListenUNIX(const char *path,
                              mode_t mask,
50
                              uid_t user,
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
                              gid_t grp,
                              virNetSocketPtr *addr);

int virNetSocketNewConnectTCP(const char *nodename,
                              const char *service,
                              virNetSocketPtr *addr);

int virNetSocketNewConnectUNIX(const char *path,
                               bool spawnDaemon,
                               const char *binary,
                               virNetSocketPtr *addr);

int virNetSocketNewConnectCommand(virCommandPtr cmd,
                                  virNetSocketPtr *retsock);

int virNetSocketNewConnectSSH(const char *nodename,
                              const char *service,
                              const char *binary,
                              const char *username,
                              bool noTTY,
71
                              bool noVerify,
72
                              const char *netcat,
73
                              const char *keyfile,
74 75 76 77 78 79 80
                              const char *path,
                              virNetSocketPtr *addr);

int virNetSocketNewConnectExternal(const char **cmdargv,
                                   virNetSocketPtr *addr);

int virNetSocketGetFD(virNetSocketPtr sock);
81 82
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);

83 84
bool virNetSocketIsLocal(virNetSocketPtr sock);

85 86
bool virNetSocketHasPassFD(virNetSocketPtr sock);

87 88
int virNetSocketGetPort(virNetSocketPtr sock);

89 90 91 92
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
                                uid_t *uid,
                                gid_t *gid,
                                pid_t *pid);
93 94 95 96 97 98 99

int virNetSocketSetBlocking(virNetSocketPtr sock,
                            bool blocking);

ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);

100
int virNetSocketSendFD(virNetSocketPtr sock, int fd);
101
int virNetSocketRecvFD(virNetSocketPtr sock, int *fd);
102

103 104 105 106 107 108 109
void virNetSocketSetTLSSession(virNetSocketPtr sock,
                               virNetTLSSessionPtr sess);
# ifdef HAVE_SASL
void virNetSocketSetSASLSession(virNetSocketPtr sock,
                                virNetSASLSessionPtr sess);
# endif
bool virNetSocketHasCachedData(virNetSocketPtr sock);
110
bool virNetSocketHasPendingData(virNetSocketPtr sock);
111
void virNetSocketRef(virNetSocketPtr sock);
112 113 114 115 116
void virNetSocketFree(virNetSocketPtr sock);

const char *virNetSocketLocalAddrString(virNetSocketPtr sock);
const char *virNetSocketRemoteAddrString(virNetSocketPtr sock);

117
int virNetSocketListen(virNetSocketPtr sock, int backlog);
118 119 120 121 122 123
int virNetSocketAccept(virNetSocketPtr sock,
                       virNetSocketPtr *clientsock);

int virNetSocketAddIOCallback(virNetSocketPtr sock,
                              int events,
                              virNetSocketIOFunc func,
124 125
                              void *opaque,
                              virFreeCallback ff);
126 127 128 129 130 131

void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
                                  int events);

void virNetSocketRemoveIOCallback(virNetSocketPtr sock);

132
void virNetSocketClose(virNetSocketPtr sock);
133 134 135


#endif /* __VIR_NET_SOCKET_H__ */