]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added comm_import_opened() to update Comm state after getting a comm_open()
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 2 May 2010 01:37:34 +0000 (19:37 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 2 May 2010 01:37:34 +0000 (19:37 -0600)
FD from another process. While both FDs point to the same kernel object, Squid
internal tables are local to each process and need to be maintained
separately.

src/comm.cc
src/comm.h

index d5b5ceb972db792ba8aa4ed40b4cc8e57c940acf..100541683c3492e34360b2371e9e18da528f2629 100644 (file)
@@ -849,6 +849,47 @@ comm_apply_flags(int new_socket,
     return new_socket;
 }
 
+void
+comm_import_opened(int fd,
+            IpAddress &addr,
+            int flags,
+            const char *note,
+            struct addrinfo *AI)
+{
+    debugs(5, 2, HERE << " FD " << fd << " at " << addr);
+    assert(fd >= 0);
+    assert(AI);
+
+    comm_init_opened(fd, addr, 0, note, AI);
+
+    if (!(flags & COMM_NOCLOEXEC))
+        fd_table[fd].flags.close_on_exec = 1;
+
+    if (addr.GetPort() > (u_short) 0) {
+#ifdef _SQUID_MSWIN_
+        if (sock_type != SOCK_DGRAM)
+#endif
+            fd_table[fd].flags.nolinger = 1;
+    }
+
+    if ((flags & COMM_TRANSPARENT))
+        fd_table[fd].flags.transparent = 1;
+
+    if (flags & COMM_NONBLOCKING)
+        fd_table[fd].flags.nonblocking = 1;
+
+#ifdef TCP_NODELAY
+    if (AI->ai_socktype == SOCK_STREAM)
+        fd_table[fd].flags.nodelay = 1;
+#endif
+
+    /* no fd_table[fd].flags. updates needed for these conditions:
+     * if ((flags & COMM_REUSEADDR)) ...
+     * if ((flags & COMM_DOBIND) ...) ...
+     */
+}
+
+
 CBDATA_CLASS_INIT(ConnectStateData);
 
 void *
index 4e289d98a51f37042ff412c7987c386c0d644d27..145a4fba05bb68fd7c509b28c8aaccc19a73896c 100644 (file)
@@ -56,6 +56,8 @@ SQUIDCEXTERN void comm_exit(void);
 
 SQUIDCEXTERN int comm_open(int, int, IpAddress &, int, const char *note);
 SQUIDCEXTERN int comm_open_uds(int sock_type, int proto, struct sockaddr_un* addr, int flags);
+/// update tables after getting a comm_open() FD from another strand
+SQUIDCEXTERN void comm_import_opened(int fd, IpAddress &addr, int flags, const char *note, struct addrinfo *AI);
 
 /**
  * Open a port specially bound for listening or sending through a specific port.