3838import io .vertx .core .internal .net .NetServerInternal ;
3939import io .vertx .core .internal .net .SslChannelProvider ;
4040import io .vertx .core .internal .net .SslHandshakeCompletionHandler ;
41+ import io .vertx .core .internal .net .TcpServerInternal ;
4142import io .vertx .core .internal .resolver .NameResolver ;
4243import io .vertx .core .internal .tls .SslContextManager ;
4344import io .vertx .core .internal .tls .SslContextProvider ;
5960 * @author <a href="http://tfox.org">Tim Fox</a>
6061 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
6162 */
62- public class TcpServerImpl implements NetServerInternal {
63+ public class TcpServerImpl implements TcpServerInternal {
6364
6465 private static final Logger log = LoggerFactory .getLogger (TcpServerImpl .class );
6566
@@ -69,7 +70,7 @@ public class TcpServerImpl implements NetServerInternal {
6970 private final boolean fileRegionEnabled ;
7071 private final boolean registerWriteHandler ;
7172 private final String protocol ;
72- private Handler <NetSocket > handler ;
73+ private Handler <TcpSocket > handler ;
7374 private Handler <Throwable > exceptionHandler ;
7475
7576 // Per server
@@ -114,12 +115,7 @@ public SslContextProvider sslContextProvider() {
114115 }
115116
116117 @ Override
117- public synchronized Handler <NetSocket > connectHandler () {
118- return handler ;
119- }
120-
121- @ Override
122- public synchronized TcpServerImpl connectHandler (Handler <NetSocket > handler ) {
118+ public synchronized TcpServerImpl connectHandler (Handler <TcpSocket > handler ) {
123119 if (isListening ()) {
124120 throw new IllegalStateException ("Cannot set connectHandler when server is listening" );
125121 }
@@ -136,11 +132,6 @@ public synchronized TcpServerImpl exceptionHandler(Handler<Throwable> handler) {
136132 return this ;
137133 }
138134
139- public int actualPort () {
140- TcpServerImpl server = actualServer ;
141- return server != null ? server .actualPort : actualPort ;
142- }
143-
144135 @ Override
145136 public Future <Void > shutdown (Duration timeout ) {
146137 ConnectionGroup group = channelGroup ;
@@ -151,22 +142,22 @@ public Future<Void> shutdown(Duration timeout) {
151142 }
152143
153144 @ Override
154- public Future <NetServer > listen (SocketAddress localAddress ) {
145+ public Future <SocketAddress > listen (SocketAddress localAddress ) {
155146 return listen (vertx .getOrCreateContext (), localAddress );
156147 }
157148
158- public Future <NetServer > listen (ContextInternal context , SocketAddress localAddress ) {
149+ public Future <SocketAddress > listen (ContextInternal context , SocketAddress localAddress ) {
159150 if (localAddress == null ) {
160151 throw new NullPointerException ("No null bind local address" );
161152 }
162153 if (handler == null ) {
163154 throw new IllegalStateException ("Set connect handler first" );
164155 }
165- return bind (context , localAddress ). map ( this ) ;
156+ return bind (context , localAddress );
166157 }
167158
168159 @ Override
169- public Future <NetServer > listen () {
160+ public Future <SocketAddress > listen () {
170161 return listen (config .getPort (), config .getHost ());
171162 }
172163
@@ -177,11 +168,11 @@ public boolean isClosed() {
177168 private class NetSocketInitializer {
178169
179170 private final ContextInternal context ;
180- private final Handler <NetSocket > connectionHandler ;
171+ private final Handler <TcpSocket > connectionHandler ;
181172 private final Handler <Throwable > exceptionHandler ;
182173 private final GlobalTrafficShapingHandler trafficShapingHandler ;
183174
184- NetSocketInitializer (ContextInternal context , Handler <NetSocket > connectionHandler , Handler <Throwable > exceptionHandler , GlobalTrafficShapingHandler trafficShapingHandler ) {
175+ NetSocketInitializer (ContextInternal context , Handler <TcpSocket > connectionHandler , Handler <Throwable > exceptionHandler , GlobalTrafficShapingHandler trafficShapingHandler ) {
185176 this .context = context ;
186177 this .connectionHandler = connectionHandler ;
187178 this .exceptionHandler = exceptionHandler ;
@@ -406,16 +397,17 @@ public void updateTrafficShapingOptions(TrafficShapingOptions options, Promise<B
406397 }
407398 }
408399
409- private synchronized Future <Channel > bind (ContextInternal context , SocketAddress localAddress ) {
400+ private synchronized Future <SocketAddress > bind (ContextInternal context , SocketAddress localAddress ) {
410401 if (listening ) {
411402 throw new IllegalStateException ("Listen already called" );
412403 }
413404
414405 this .listening = true ;
415406 this .eventLoop = context .nettyEventLoop ();
416407
408+ PromiseInternal <Channel > promise = context .promise ();
417409 SocketAddress bindAddress ;
418- Map <ServerID , NetServerInternal > sharedNetServers = vertx .sharedTcpServers ();
410+ Map <ServerID , TcpServerInternal > sharedNetServers = ( Map ) vertx .sharedTcpServers ();
419411 synchronized (sharedNetServers ) {
420412 actualPort = localAddress .port ();
421413 String hostOrPath = localAddress .isInetSocket () ? localAddress .host () : localAddress .path ();
@@ -451,7 +443,6 @@ protected void handleShutdown(Duration timeout, Completable<Void> completion) {
451443 }
452444 };
453445 channelGroup = group ;
454- PromiseInternal <Channel > promise = context .promise ();
455446 if (main == null ) {
456447
457448 SslContextManager helper ;
@@ -508,8 +499,6 @@ protected void handleShutdown(Duration timeout, Completable<Void> completion) {
508499 }
509500 listening = false ;
510501 });
511-
512- return bindFuture ;
513502 } else {
514503 // Server already exists with that host/port - we will use that
515504 actualServer = main ;
@@ -523,9 +512,11 @@ protected void handleShutdown(Duration timeout, Completable<Void> completion) {
523512 };
524513 actualServer .channelBalancer .addWorker (eventLoop , worker );
525514 main .bindFuture .onComplete (promise );
526- return promise .future ();
527515 }
528516 }
517+ return promise
518+ .future ()
519+ .map (ch -> vertx .transport ().convert (ch .localAddress ()));
529520 }
530521
531522 private void bind (
@@ -535,7 +526,7 @@ private void bind(
535526 SocketAddress localAddress ,
536527 boolean shared ,
537528 Promise <Channel > promise ,
538- Map <ServerID , NetServerInternal > sharedNetServers ,
529+ Map <ServerID , TcpServerInternal > sharedNetServers ,
539530 ServerID id ) {
540531 // Socket bind
541532 channelBalancer .addWorker (eventLoop , worker );
0 commit comments