mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge tag 'win-socket-pull-request' of https://gitlab.com/marcandre.lureau/qemu into staging
QMP command to import win32 sockets # -----BEGIN PGP SIGNATURE----- # # iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmQPDQ0cHG1hcmNhbmRy # ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5eTUD/41+bodkctP9wtNQT5g # 4P2XQysa9dhxIaQuPT48J5bN0velOAv+p+e9jNMojVPHogACRGkjJUGrh2AhaWJO # bpqB5teNz3pbTLAHNrqiJdUrJDI0WSqBN2q7WgfbzvHMugBqul13n6UG/cVWH8D3 # pDX3miBl9Cv3zUDFzPjHH3eR/MHz+6wXmuzUGQdWqyGBoLwqgWA3Bqh39BDVOeJf # 03Kq3TbJSP096EjGGrq1pTYDIIv9AKzUWgn8tT8S73sD3J0BN28Gl5HirXDx8e/4 # 2WtW/XLYKjqoUl7RmXOjfOarCV+kxzdoYCAUYfyH6DLWrkXc41L5ugFdyxxQ66Sh # +on7hKCBzPEOPEXmlm6HlMj3bK4C/GI6mIoaZgCrsvj9xlehhQNtwpndAwAR8esH # perQ6q+jPdoQnBvOBgC3amckS1kYdbQivTILkoopumw/q4waG5reyA4rshbhm/bs # U33ZRzob0XyRWqvWAcq9hnWB5gvQCcppeJlu60gocnX5wdZOjbnsBXw3l+r2osIh # izJbxwM6xmz9oHh50nhDCn42JrNdSnZJdJ/XA/lrOkTHQ6kbZO7v86Y/mKQz+Vyx # Uyhb8/y8gKrUkZlGCEMvQVcyvOA8vneX8WhfZUm6w5MWWCNKfCrEl6UGmFkPAL0m # +sUYIhN5PSxWSQU5MWogXtQEPA== # =/Y/7 # -----END PGP SIGNATURE----- # gpg: Signature made Mon 13 Mar 2023 11:46:21 GMT # gpg: using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5 # gpg: issuer "marcandre.lureau@redhat.com" # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full] # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full] # Primary key fingerprint: 87A9 BD93 3F87 C606 D276 F62D DAE8 E109 7596 9CE5 * tag 'win-socket-pull-request' of https://gitlab.com/marcandre.lureau/qemu: (25 commits) monitor: restrict command getfd to POSIX hosts qtest: enable vnc-display test on win32 libqtest: make qtest_qmp_add_client work on win32 qmp: add 'get-win32-socket' monitor: release the lock before calling close() qmp: 'add_client' actually expects sockets osdep: implement qemu_socketpair() for win32 tests/docker: fix a win32 error due to portability char: do not double-close fd when failing to add client tests: fix path separator, use g_build_filename() win32: replace closesocket() with close() wrapper os-posix: remove useless ioctlsocket() define win32: avoid mixing SOCKET and file descriptor space slirp: open-code qemu_socket_(un)select() slirp: unregister the win32 SOCKET main-loop: remove qemu_fd_register(), win32/slirp/socket specific aio/win32: aio_set_fd_handler() only supports SOCKET aio: make aio_set_fd_poll() static to aio-posix.c win32/socket: introduce qemu_socket_unselect() helper win32/socket: introduce qemu_socket_select() helper ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -573,13 +573,13 @@ static int tpm_emulator_prepare_data_fd(TPMEmulator *tpm_emu)
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
closesocket(fds[1]);
|
||||
close(fds[1]);
|
||||
|
||||
return 0;
|
||||
|
||||
err_exit:
|
||||
closesocket(fds[0]);
|
||||
closesocket(fds[1]);
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1175,12 +1175,10 @@ bool qmp_add_client_char(int fd, bool has_skipauth, bool skipauth,
|
||||
|
||||
if (!s) {
|
||||
error_setg(errp, "protocol '%s' is invalid", protocol);
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
if (qemu_chr_add_client(s, fd) < 0) {
|
||||
error_setg(errp, "failed to add client");
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ qcrypto_afalg_socket_bind(const char *type, const char *name,
|
||||
|
||||
if (bind(sbind, (const struct sockaddr *)&salg, sizeof(salg)) != 0) {
|
||||
error_setg_errno(errp, errno, "Failed to bind socket");
|
||||
closesocket(sbind);
|
||||
close(sbind);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -105,11 +105,11 @@ void qcrypto_afalg_comm_free(QCryptoAFAlg *afalg)
|
||||
}
|
||||
|
||||
if (afalg->tfmfd != -1) {
|
||||
closesocket(afalg->tfmfd);
|
||||
close(afalg->tfmfd);
|
||||
}
|
||||
|
||||
if (afalg->opfd != -1) {
|
||||
closesocket(afalg->opfd);
|
||||
close(afalg->opfd);
|
||||
}
|
||||
|
||||
g_free(afalg);
|
||||
|
||||
@@ -1486,6 +1486,7 @@ SRST
|
||||
Inject an MCE on the given CPU (x86 only).
|
||||
ERST
|
||||
|
||||
#ifdef CONFIG_POSIX
|
||||
{
|
||||
.name = "getfd",
|
||||
.args_type = "fdname:s",
|
||||
@@ -1501,6 +1502,7 @@ SRST
|
||||
mechanism on unix sockets, it is stored using the name *fdname* for
|
||||
later use by other monitor commands.
|
||||
ERST
|
||||
#endif
|
||||
|
||||
{
|
||||
.name = "closefd",
|
||||
|
||||
+2
-2
@@ -340,7 +340,7 @@ static void hv_syndbg_realize(DeviceState *dev, Error **errp)
|
||||
syndbg->servaddr.sin_family = AF_INET;
|
||||
if (connect(syndbg->socket, (struct sockaddr *)&syndbg->servaddr,
|
||||
sizeof(syndbg->servaddr)) < 0) {
|
||||
closesocket(syndbg->socket);
|
||||
close(syndbg->socket);
|
||||
error_setg(errp, "%s failed to connect to socket", TYPE_HV_SYNDBG);
|
||||
return;
|
||||
}
|
||||
@@ -357,7 +357,7 @@ static void hv_syndbg_unrealize(DeviceState *dev)
|
||||
|
||||
if (syndbg->socket > 0) {
|
||||
qemu_set_fd_handler(syndbg->socket, NULL, NULL, NULL);
|
||||
closesocket(syndbg->socket);
|
||||
close(syndbg->socket);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -482,14 +482,6 @@ void aio_set_fd_handler(AioContext *ctx,
|
||||
IOHandler *io_poll_ready,
|
||||
void *opaque);
|
||||
|
||||
/* Set polling begin/end callbacks for a file descriptor that has already been
|
||||
* registered with aio_set_fd_handler. Do nothing if the file descriptor is
|
||||
* not registered.
|
||||
*/
|
||||
void aio_set_fd_poll(AioContext *ctx, int fd,
|
||||
IOHandler *io_poll_begin,
|
||||
IOHandler *io_poll_end);
|
||||
|
||||
/* Register an event notifier and associated callbacks. Behaves very similarly
|
||||
* to event_notifier_set_handler. Unlike event_notifier_set_handler, these callbacks
|
||||
* will be invoked when using aio_poll().
|
||||
|
||||
@@ -519,6 +519,12 @@ static inline void error_propagator_cleanup(ErrorPropagator *prop)
|
||||
|
||||
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
|
||||
|
||||
/*
|
||||
* Special error destination to warn on error.
|
||||
* See error_setg() and error_propagate() for details.
|
||||
*/
|
||||
extern Error *error_warn;
|
||||
|
||||
/*
|
||||
* Special error destination to abort on error.
|
||||
* See error_setg() and error_propagate() for details.
|
||||
|
||||
@@ -387,8 +387,6 @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
|
||||
|
||||
/* internal interfaces */
|
||||
|
||||
void qemu_fd_register(int fd);
|
||||
|
||||
#define qemu_bh_new(cb, opaque) \
|
||||
qemu_bh_new_full((cb), (opaque), (stringify(cb)))
|
||||
QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name);
|
||||
|
||||
@@ -665,20 +665,6 @@ void qemu_prealloc_mem(int fd, char *area, size_t sz, int max_threads,
|
||||
*/
|
||||
char *qemu_get_pid_name(pid_t pid);
|
||||
|
||||
/**
|
||||
* qemu_fork:
|
||||
*
|
||||
* A version of fork that avoids signal handler race
|
||||
* conditions that can lead to child process getting
|
||||
* signals that are otherwise only expected by the
|
||||
* parent. It also resets all signal handlers to the
|
||||
* default settings.
|
||||
*
|
||||
* Returns 0 to child process, pid number to parent
|
||||
* or -1 on failure.
|
||||
*/
|
||||
pid_t qemu_fork(Error **errp);
|
||||
|
||||
/* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
|
||||
* when intptr_t is 32-bit and we are aligning a long long.
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,6 @@ int inet_aton(const char *cp, struct in_addr *ia);
|
||||
bool fd_is_socket(int fd);
|
||||
int qemu_socket(int domain, int type, int protocol);
|
||||
|
||||
#ifndef WIN32
|
||||
/**
|
||||
* qemu_socketpair:
|
||||
* @domain: specifies a communication domain, such as PF_UNIX
|
||||
@@ -30,7 +29,6 @@ int qemu_socket(int domain, int type, int protocol);
|
||||
* Return 0 on success.
|
||||
*/
|
||||
int qemu_socketpair(int domain, int type, int protocol, int sv[2]);
|
||||
#endif
|
||||
|
||||
int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
||||
/*
|
||||
|
||||
@@ -51,9 +51,6 @@ void os_daemonize(void);
|
||||
void os_setup_post(void);
|
||||
int os_mlock(void);
|
||||
|
||||
#define closesocket(s) close(s)
|
||||
#define ioctlsocket(s, r, v) ioctl(s, r, v)
|
||||
|
||||
int os_set_daemonize(bool d);
|
||||
bool is_daemonized(void);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include "qemu/typedefs.h"
|
||||
|
||||
#ifdef HAVE_AFUNIX_H
|
||||
#include <afunix.h>
|
||||
@@ -164,10 +165,20 @@ static inline void qemu_funlockfile(FILE *f)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Helper for WSAEventSelect, to report errors */
|
||||
bool qemu_socket_select(int sockfd, WSAEVENT hEventObject,
|
||||
long lNetworkEvents, Error **errp);
|
||||
|
||||
bool qemu_socket_unselect(int sockfd, Error **errp);
|
||||
|
||||
/* We wrap all the sockets functions so that we can
|
||||
* set errno based on WSAGetLastError()
|
||||
*/
|
||||
|
||||
#undef close
|
||||
#define close qemu_close_wrap
|
||||
int qemu_close_wrap(int fd);
|
||||
|
||||
#undef connect
|
||||
#define connect qemu_connect_wrap
|
||||
int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
|
||||
@@ -199,10 +210,6 @@ int qemu_shutdown_wrap(int sockfd, int how);
|
||||
#define ioctlsocket qemu_ioctlsocket_wrap
|
||||
int qemu_ioctlsocket_wrap(int fd, int req, void *val);
|
||||
|
||||
#undef closesocket
|
||||
#define closesocket qemu_closesocket_wrap
|
||||
int qemu_closesocket_wrap(int fd);
|
||||
|
||||
#undef getsockopt
|
||||
#define getsockopt qemu_getsockopt_wrap
|
||||
int qemu_getsockopt_wrap(int sockfd, int level, int optname,
|
||||
|
||||
+4
-4
@@ -442,9 +442,9 @@ static void qio_channel_socket_finalize(Object *obj)
|
||||
}
|
||||
}
|
||||
#ifdef WIN32
|
||||
WSAEventSelect(ioc->fd, NULL, 0);
|
||||
qemu_socket_unselect(ioc->fd, NULL);
|
||||
#endif
|
||||
closesocket(ioc->fd);
|
||||
close(ioc->fd);
|
||||
ioc->fd = -1;
|
||||
}
|
||||
}
|
||||
@@ -846,13 +846,13 @@ qio_channel_socket_close(QIOChannel *ioc,
|
||||
|
||||
if (sioc->fd != -1) {
|
||||
#ifdef WIN32
|
||||
WSAEventSelect(sioc->fd, NULL, 0);
|
||||
qemu_socket_unselect(sioc->fd, NULL);
|
||||
#endif
|
||||
if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_LISTEN)) {
|
||||
socket_listen_cleanup(sioc->fd, errp);
|
||||
}
|
||||
|
||||
if (closesocket(sioc->fd) < 0) {
|
||||
if (close(sioc->fd) < 0) {
|
||||
sioc->fd = -1;
|
||||
error_setg_errno(&err, errno, "Unable to close socket");
|
||||
error_propagate(errp, err);
|
||||
|
||||
+5
-5
@@ -275,15 +275,15 @@ GSource *qio_channel_create_fd_watch(QIOChannel *ioc,
|
||||
|
||||
#ifdef CONFIG_WIN32
|
||||
GSource *qio_channel_create_socket_watch(QIOChannel *ioc,
|
||||
int socket,
|
||||
int sockfd,
|
||||
GIOCondition condition)
|
||||
{
|
||||
GSource *source;
|
||||
QIOChannelSocketSource *ssource;
|
||||
|
||||
WSAEventSelect(socket, ioc->event,
|
||||
FD_READ | FD_ACCEPT | FD_CLOSE |
|
||||
FD_CONNECT | FD_WRITE | FD_OOB);
|
||||
qemu_socket_select(sockfd, ioc->event,
|
||||
FD_READ | FD_ACCEPT | FD_CLOSE |
|
||||
FD_CONNECT | FD_WRITE | FD_OOB, NULL);
|
||||
|
||||
source = g_source_new(&qio_channel_socket_source_funcs,
|
||||
sizeof(QIOChannelSocketSource));
|
||||
@@ -293,7 +293,7 @@ GSource *qio_channel_create_socket_watch(QIOChannel *ioc,
|
||||
object_ref(OBJECT(ioc));
|
||||
|
||||
ssource->condition = condition;
|
||||
ssource->socket = socket;
|
||||
ssource->socket = _get_osfhandle(sockfd);
|
||||
ssource->revents = 0;
|
||||
|
||||
ssource->fd.fd = (gintptr)ioc->event;
|
||||
|
||||
+76
-27
@@ -61,11 +61,48 @@ struct MonFdset {
|
||||
static QemuMutex mon_fdsets_lock;
|
||||
static QLIST_HEAD(, MonFdset) mon_fdsets;
|
||||
|
||||
static bool monitor_add_fd(Monitor *mon, int fd, const char *fdname, Error **errp)
|
||||
{
|
||||
mon_fd_t *monfd;
|
||||
|
||||
if (qemu_isdigit(fdname[0])) {
|
||||
close(fd);
|
||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
|
||||
"a name not starting with a digit");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* See close() call below. */
|
||||
qemu_mutex_lock(&mon->mon_lock);
|
||||
QLIST_FOREACH(monfd, &mon->fds, next) {
|
||||
int tmp_fd;
|
||||
|
||||
if (strcmp(monfd->name, fdname) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp_fd = monfd->fd;
|
||||
monfd->fd = fd;
|
||||
qemu_mutex_unlock(&mon->mon_lock);
|
||||
/* Make sure close() is outside critical section */
|
||||
close(tmp_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
monfd = g_new0(mon_fd_t, 1);
|
||||
monfd->name = g_strdup(fdname);
|
||||
monfd->fd = fd;
|
||||
|
||||
QLIST_INSERT_HEAD(&mon->fds, monfd, next);
|
||||
qemu_mutex_unlock(&mon->mon_lock);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_POSIX
|
||||
void qmp_getfd(const char *fdname, Error **errp)
|
||||
{
|
||||
Monitor *cur_mon = monitor_cur();
|
||||
mon_fd_t *monfd;
|
||||
int fd, tmp_fd;
|
||||
int fd;
|
||||
|
||||
fd = qemu_chr_fe_get_msgfd(&cur_mon->chr);
|
||||
if (fd == -1) {
|
||||
@@ -73,32 +110,9 @@ void qmp_getfd(const char *fdname, Error **errp)
|
||||
return;
|
||||
}
|
||||
|
||||
if (qemu_isdigit(fdname[0])) {
|
||||
close(fd);
|
||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
|
||||
"a name not starting with a digit");
|
||||
return;
|
||||
}
|
||||
|
||||
QEMU_LOCK_GUARD(&cur_mon->mon_lock);
|
||||
QLIST_FOREACH(monfd, &cur_mon->fds, next) {
|
||||
if (strcmp(monfd->name, fdname) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp_fd = monfd->fd;
|
||||
monfd->fd = fd;
|
||||
/* Make sure close() is outside critical section */
|
||||
close(tmp_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
monfd = g_new0(mon_fd_t, 1);
|
||||
monfd->name = g_strdup(fdname);
|
||||
monfd->fd = fd;
|
||||
|
||||
QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
|
||||
monitor_add_fd(cur_mon, fd, fdname, errp);
|
||||
}
|
||||
#endif
|
||||
|
||||
void qmp_closefd(const char *fdname, Error **errp)
|
||||
{
|
||||
@@ -211,6 +225,41 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
void qmp_get_win32_socket(const char *infos, const char *fdname, Error **errp)
|
||||
{
|
||||
g_autofree WSAPROTOCOL_INFOW *info = NULL;
|
||||
gsize len;
|
||||
SOCKET sk;
|
||||
int fd;
|
||||
|
||||
info = (void *)g_base64_decode(infos, &len);
|
||||
if (len != sizeof(*info)) {
|
||||
error_setg(errp, "Invalid WSAPROTOCOL_INFOW value");
|
||||
return;
|
||||
}
|
||||
|
||||
sk = WSASocketW(FROM_PROTOCOL_INFO,
|
||||
FROM_PROTOCOL_INFO,
|
||||
FROM_PROTOCOL_INFO,
|
||||
info, 0, 0);
|
||||
if (sk == INVALID_SOCKET) {
|
||||
error_setg_win32(errp, WSAGetLastError(), "Couldn't import socket");
|
||||
return;
|
||||
}
|
||||
|
||||
fd = _open_osfhandle(sk, _O_BINARY);
|
||||
if (fd < 0) {
|
||||
error_setg_errno(errp, errno, "Failed to associate a FD with the SOCKET");
|
||||
closesocket(sk);
|
||||
return;
|
||||
}
|
||||
|
||||
monitor_add_fd(monitor_cur(), fd, fdname, errp);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void qmp_remove_fd(int64_t fdset_id, bool has_fd, int64_t fd, Error **errp)
|
||||
{
|
||||
MonFdset *mon_fdset;
|
||||
|
||||
@@ -192,6 +192,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
|
||||
hmp_handle_error(mon, err);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_POSIX
|
||||
void hmp_getfd(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
const char *fdname = qdict_get_str(qdict, "fdname");
|
||||
@@ -200,6 +201,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict)
|
||||
qmp_getfd(fdname, &err);
|
||||
hmp_handle_error(mon, err);
|
||||
}
|
||||
#endif
|
||||
|
||||
void hmp_closefd(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "monitor-internal.h"
|
||||
#include "monitor/qdev.h"
|
||||
#include "monitor/qmp-helpers.h"
|
||||
@@ -139,6 +140,12 @@ void qmp_add_client(const char *protocol, const char *fdname,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fd_is_socket(fd)) {
|
||||
error_setg(errp, "parameter @fdname must name a socket");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(protocol_table); i++) {
|
||||
if (!strcmp(protocol, protocol_table[i].name)) {
|
||||
if (!protocol_table[i].add_client(fd, has_skipauth, skipauth,
|
||||
|
||||
+7
-7
@@ -230,7 +230,7 @@ static int net_dgram_mcast_create(struct sockaddr_in *mcastaddr,
|
||||
return fd;
|
||||
fail:
|
||||
if (fd >= 0) {
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ static int net_dgram_mcast_init(NetClientState *peer,
|
||||
if (convert_host_port(saddr, local->u.inet.host, local->u.inet.port,
|
||||
errp) < 0) {
|
||||
g_free(saddr);
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -360,14 +360,14 @@ static int net_dgram_mcast_init(NetClientState *peer,
|
||||
if (saddr->sin_addr.s_addr == 0) {
|
||||
error_setg(errp, "can't setup multicast destination address");
|
||||
g_free(saddr);
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
/* clone dgram socket */
|
||||
newfd = net_dgram_mcast_create(saddr, NULL, errp);
|
||||
if (newfd < 0) {
|
||||
g_free(saddr);
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
/* clone newfd to fd, close newfd */
|
||||
@@ -494,14 +494,14 @@ int net_init_dgram(const Netdev *netdev, const char *name,
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno,
|
||||
"can't set socket option SO_REUSEADDR");
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ret = bind(fd, (struct sockaddr *)&laddr_in, sizeof(laddr_in));
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
||||
inet_ntoa(laddr_in.sin_addr));
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
qemu_socket_set_nonblock(fd);
|
||||
@@ -548,7 +548,7 @@ int net_init_dgram(const Netdev *netdev, const char *name,
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno, "can't bind unix=%s to socket",
|
||||
laddr_un.sun_path);
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
qemu_socket_set_nonblock(fd);
|
||||
|
||||
+14
-2
@@ -248,12 +248,24 @@ static void net_slirp_timer_mod(void *timer, int64_t expire_timer,
|
||||
|
||||
static void net_slirp_register_poll_fd(int fd, void *opaque)
|
||||
{
|
||||
qemu_fd_register(fd);
|
||||
#ifdef WIN32
|
||||
AioContext *ctxt = qemu_get_aio_context();
|
||||
|
||||
if (WSAEventSelect(fd, event_notifier_get_handle(&ctxt->notifier),
|
||||
FD_READ | FD_ACCEPT | FD_CLOSE |
|
||||
FD_CONNECT | FD_WRITE | FD_OOB) != 0) {
|
||||
error_setg_win32(&error_warn, WSAGetLastError(), "failed to WSAEventSelect()");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void net_slirp_unregister_poll_fd(int fd, void *opaque)
|
||||
{
|
||||
/* no qemu_fd_unregister */
|
||||
#ifdef WIN32
|
||||
if (WSAEventSelect(fd, NULL, 0) != 0) {
|
||||
error_setg_win32(&error_warn, WSAGetLastError(), "failed to WSAEventSelect()");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void net_slirp_notify(void *opaque)
|
||||
|
||||
+11
-11
@@ -172,7 +172,7 @@ static void net_socket_send(void *opaque)
|
||||
if (s->listen_fd != -1) {
|
||||
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
|
||||
}
|
||||
closesocket(s->fd);
|
||||
close(s->fd);
|
||||
|
||||
s->fd = -1;
|
||||
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
|
||||
@@ -299,7 +299,7 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr,
|
||||
return fd;
|
||||
fail:
|
||||
if (fd >= 0)
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ static void net_socket_cleanup(NetClientState *nc)
|
||||
}
|
||||
if (s->listen_fd != -1) {
|
||||
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
|
||||
closesocket(s->listen_fd);
|
||||
close(s->listen_fd);
|
||||
s->listen_fd = -1;
|
||||
}
|
||||
}
|
||||
@@ -399,7 +399,7 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
|
||||
return s;
|
||||
|
||||
err:
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,
|
||||
if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&so_type,
|
||||
(socklen_t *)&optlen)< 0) {
|
||||
error_setg(errp, "can't get socket option SO_TYPE");
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
switch(so_type) {
|
||||
@@ -468,7 +468,7 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,
|
||||
default:
|
||||
error_setg(errp, "socket type=%d for fd=%d must be either"
|
||||
" SOCK_DGRAM or SOCK_STREAM", so_type, fd);
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -526,13 +526,13 @@ static int net_socket_listen_init(NetClientState *peer,
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
||||
inet_ntoa(saddr.sin_addr));
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ret = listen(fd, 0);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno, "can't listen on socket");
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -579,7 +579,7 @@ static int net_socket_connect_init(NetClientState *peer,
|
||||
break;
|
||||
} else {
|
||||
error_setg_errno(errp, errno, "can't connect socket");
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@@ -671,14 +671,14 @@ static int net_socket_udp_init(NetClientState *peer,
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno,
|
||||
"can't set socket option SO_REUSEADDR");
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, errno, "can't bind ip=%s to socket",
|
||||
inet_ntoa(laddr.sin_addr));
|
||||
closesocket(fd);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
qemu_socket_set_nonblock(fd);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user