2011/10/14 Henri Gomez <henri.go...@gmail.com>: >>> 3) There are several Connector/Endpoint implementations in Tomcat. >>> While java.net.ServerSocket does support port number of "0", I am not >>> sure that APR-based implementation does allow it. >> Sure but the use case is just to start a http/https (apr can be >> omitted) connector on any random free port, do some unit test and stop >> it. >> IMHO it's a valid use case (and with it folks will be able to use >> tomcat rather than an other servlet container which has this feature >> available :-) ). >> See the code snippet I have pointed, the code to write for using >> tomcat is really smaller/smarter (except all hacking I have to write >> due to the restriction on port). > > Guys. > > It make sense to have a way to get an unused random port for embedded > mode in testing cases. > > On a CI system, ie Jenkins, you could have many concurrents tests done > at the same time, the only solution to get a free port is to discover > it at startup time isn't it ? >
Well, after some research, using some random port for bind(0) seems to be a kernel feature. I cannot confirm that apr_socket_bind can accept 0 as port number [1], but seems that allowing 0 will use less resources than trying to programmatically select a random port and retry on failure. [1] http://apr.apache.org/docs/apr/1.4/group__apr__network__io.html So maybe let's go with this and document that support for "0" depends on platform and connector implementation. I think that the value of "-1" could be officially used to disable the connector (prevent it from binding and starting). I think "-1" can be used as the initial value for Connector#port as well, and that this value can be used to re-implement the check in http://svn.apache.org/viewvc?view=revision&revision=1147949 Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org