Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumphijack Do the standard dance for sendto/recvfrom ...



details:   https://anonhg.NetBSD.org/src/rev/5b98964ceaf6
branches:  trunk
changeset: 761049:5b98964ceaf6
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed Jan 19 11:27:01 2011 +0000

description:
Do the standard dance for sendto/recvfrom since nspluginwrapper
wants to use them.  XXX: need to fold the dance sequence into a
common routine.

diffstat:

 lib/librumphijack/hijack.c |  32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)

diffs (75 lines):

diff -r 898bd695357f -r 5b98964ceaf6 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c        Wed Jan 19 11:02:00 2011 +0000
+++ b/lib/librumphijack/hijack.c        Wed Jan 19 11:27:01 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: hijack.c,v 1.15 2011/01/18 23:43:21 pooka Exp $       */
+/*      $NetBSD: hijack.c,v 1.16 2011/01/19 11:27:01 pooka Exp $       */
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.15 2011/01/18 23:43:21 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.16 2011/01/19 11:27:01 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -116,6 +116,9 @@
 static pid_t   (*host_fork)(void);
 static int     (*host_dup2)(int, int);
 static int     (*host_shutdown)(int, int);
+/* XXX */
+static void    *host_sendto;
+static void    *host_recvfrom;
 
 static void *rumpcalls[RUMPCALL__NUM];
 
@@ -189,6 +192,8 @@
        host_fork = dlsym(RTLD_NEXT, "fork");
        host_dup2 = dlsym(RTLD_NEXT, "dup2");
        host_shutdown = dlsym(RTLD_NEXT, "shutdown");
+       host_sendto = dlsym(RTLD_NEXT, "sendto");
+       host_recvfrom = dlsym(RTLD_NEXT, "recvfrom");
 
        for (i = 0; i < RUMPCALL__NUM; i++) {
                rumpcalls[i] = dlsym(hand, sysnames[i]);
@@ -401,9 +406,14 @@
            struct sockaddr *, socklen_t *);
 
        DPRINTF(("recvfrom\n"));
-       assertfd(s);
-       rc_recvfrom = rumpcalls[RUMPCALL_RECVFROM];
-       return rc_recvfrom(fd_host2rump(s), buf, len, flags, from, fromlen);
+       if (fd_isrump(s)) {
+               rc_recvfrom = rumpcalls[RUMPCALL_RECVFROM];
+               s = fd_host2rump(s);
+       } else {
+               rc_recvfrom = host_recvfrom;
+       }
+
+       return rc_recvfrom(s, buf, len, flags, from, fromlen);
 }
 
 ssize_t
@@ -433,11 +443,15 @@
 
        if (s == -1)
                return len;
+       DPRINTF(("sendto\n"));
 
-       DPRINTF(("sendto\n"));
-       assertfd(s);
-       rc_sendto = rumpcalls[RUMPCALL_SENDTO];
-       return rc_sendto(fd_host2rump(s), buf, len, flags, to, tolen);
+       if (fd_isrump(s)) {
+               rc_sendto = rumpcalls[RUMPCALL_SENDTO];
+               s = fd_host2rump(s);
+       } else {
+               rc_sendto = host_sendto;
+       }
+       return rc_sendto(s, buf, len, flags, to, tolen);
 }
 
 ssize_t



Home | Main Index | Thread Index | Old Index