Am 02.10.20 um 00:53 schrieb Vladislav Grishenko: > For non-blocking TCP/Unix connection, OpenVPN checks was it established in > loop and if not - sleeps or handles management for next one second. Since > the first check is made right after the connection attempt, it will likely > be always unsuccessful, causing redundant wait for one or more seconds: > > 00:00:00.667607 fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0 > 00:00:00.667713 connect(5, {...}, 16) = -1 EINPROGRESS (Operation now in > progress) > 00:00:00.667832 poll([{fd=5, events=POLLOUT}], 1, 0) = 0 (Timeout) > 00:00:00.667954 nanosleep({tv_sec=1, tv_nsec=0}, 0x7fff52450270) = 0 > 00:00:01.668608 poll([{fd=5, events=POLLOUT}], 1, 0) = 1 ([{fd=5, > revents=POLLOUT}]) > > After this patch openvpn_connect() will perform blocking wait for connection > establishment (if possible) and just check for management events once in one > second (if management enabled) w/o sleep. This speedups TCP/Unix connection > establishment and provides almost real connection time that can be used for > detection of the fastest remote server in subsequent patches: > > 00:00:00.790510 fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0 > 00:00:00.790616 connect(5, {...}, 16) = -1 EINPROGRESS (Operation now in > progress) > 00:00:00.790877 poll([{fd=5, events=POLLOUT}], 1, 1000) = 0 (Timeout) > 00:00:01.792880 poll([{fd=5, events=POLLOUT}], 1, 1000) = 1 ([{fd=5, > revents=POLLOUT}]) > > Or, with management interface enabled: > > 00:00:00.906421 fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0 > 00:00:00.906527 connect(6, {...}, 16) = -1 EINPROGRESS (Operation now in > progress) > 00:00:00.906779 poll([{fd=6, events=POLLOUT}], 1, 1000) = 0 (Timeout) > 00:00:01.910418 poll([{fd=3, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout) > 00:00:01.911365 poll([{fd=6, events=POLLOUT}], 1, 1000) = 0 ([{fd=6, > revents=POLLOUT}]) > > v2: cosmetics, decrease connection_timeout to avoid wait more than it > v3: teach management_sleep() to handle zero timeout and reject negative > use 1s timeout for connection and 0s timeout for management events
I like this version much more. It doesn't add extra complexity. Acked-By: Arne Schwabe <a...@rfc2549.org>
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel