Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Unified Diff: dart/runtime/bin/socket.h

Issue 879353003: Introduce optional 'bool shared' parameter to ServerSocket.bind() ... (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: dart/runtime/bin/socket.h
diff --git a/dart/runtime/bin/socket.h b/dart/runtime/bin/socket.h
index ff5444daa585f4546d8c2421e657565bd99e393b..c84bdd8953aa7f093d89210b5665d49b0f2bf63a 100644
--- a/dart/runtime/bin/socket.h
+++ b/dart/runtime/bin/socket.h
@@ -5,6 +5,8 @@
#ifndef BIN_SOCKET_H_
#define BIN_SOCKET_H_
+#include <map>
Søren Gjesse 2015/01/29 09:05:51 As some point we where avoiding using STL, which i
kustermann 2015/01/29 11:14:05 Yes, I thought there might be a 50/50 chance of be
+
#include "platform/globals.h"
#include "bin/builtin.h"
@@ -312,6 +314,77 @@ class ServerSocket {
DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket);
};
+class ListeningSocketRegistry {
+ private:
+ struct OSSocket {
+ RawAddr address;
+ int port;
+ bool v6_only;
+ bool shared;
+ int ref_count;
+ int socketfd;
Søren Gjesse 2015/01/29 09:05:51 To support Windows where this is a pointer this sh
kustermann 2015/01/29 11:14:05 Done.
+
+ // Singly linked lists of OSSocket instances which listen on the same port
+ // but on different addresses.
+ OSSocket *next;
+
+ OSSocket(RawAddr address, int port, bool v6_only, bool shared, int socketfd)
+ : address(address), port(port), v6_only(v6_only), shared(shared),
+ ref_count(0), socketfd(socketfd), next(NULL) {}
+ };
+ typedef std::map<int, OSSocket*>::iterator SocketsIterator;
+
+ public:
+ ListeningSocketRegistry() : mutex_(new Mutex()) {}
+
+ // This function should be called from a dart runtime call in order to create
+ // a new (potentially shared) socket.
+ Dart_Handle CreateBindListen(Dart_Handle socket_object,
+ RawAddr addr,
+ intptr_t port,
+ intptr_t backlog,
+ bool v6_only,
+ bool shared);
+
+ // This should be called from the event handler for every kCloseEvent it gets
+ // on listening sockets.
+ //
+ // Returns `true` if the last reference has been droped and the underlying
wibling 2015/01/29 09:42:01 NIT: droped -> dropped
kustermann 2015/01/29 11:14:05 Done.
+ // socket can be closed.
+ //
+ // The caller is responsible for obtaining the mutex first, before calling
+ // this function.
+ bool CloseSafe(int socketfd);
+
+ // Mark an existing socket as sharable if it is not already marked as
+ // sharable.
+ //
+ // NOTE: This is a temporary measure until ServerSocketReferenc'es are
wibling 2015/01/29 09:42:01 NIT: ServerSocketReferenc'es -> ServerSocketRefere
kustermann 2015/01/29 11:14:05 Done.
+ // removed.
+ Dart_Handle MarkSocketFdAsSharableHack(int socketfd);
+
+ Mutex *mutex() { return mutex_; }
+
+ private:
+ bool addressesAreEqual(const RawAddr& a, const RawAddr& b);
+
+ OSSocket *findOSSocketWithAddress(OSSocket *current, const RawAddr& addr) {
+ while (current != NULL) {
+ if (addressesAreEqual(current->address, addr)) {
+ return current;
+ }
+ current = current->next;
+ }
+ return NULL;
+ }
+
+ std::map<int, OSSocket*> sockets_by_port_;
+ std::map<int, OSSocket*> sockets_by_fd_;
+ Mutex *mutex_;
+};
+
+extern ListeningSocketRegistry globalTcpListeningSocketRegistry;
+
} // namespace bin
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698