MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 2 | #include <comm.h> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 3 | int net_connect(string host, int port) |
| 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 5 | DESCRIPTION |
| 6 | Open a non-blocking TCP network connection to <host> and |
| 7 | <port>. On success, the connection is bound to the current |
| 8 | object and the lfun logon() is called in the object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 10 | Returns one of the following values: |
| 11 | NC_SUCCESS Success |
| 12 | NC_EUNKNOWNHOST the host address could not be resolved |
| 13 | NC_ENOSOCKET error during socket creation |
| 14 | NC_ENOBIND socket could not be bound |
| 15 | NC_ENOCONNECT socket could not be connected |
| 16 | (Details of the last three errors can be found in the driver's error |
| 17 | log.) |
| 18 | NC_ECONNREFUSED remote host not listening/refusing |
| 19 | NC_EMCONN too many pending connections (transient, try |
| 20 | again later) |
| 21 | NC_ENORESSOURCES insufficient system ressources (transient, try |
| 22 | again later) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 23 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 24 | If the driver is configured to support IPv6, <host> is first |
| 25 | interpreted as IPv6 hostname. If that fails, <host> is then |
| 26 | interpretd as IPv4 hostname. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 28 | If the connection can't be established immediately, the efun |
| 29 | returns 'success' and the driver will check in the background |
| 30 | for the progress of the connection. When it is established, |
| 31 | logon() will be called in the object. If the connection fails, |
| 32 | logon(-1) will be called in the object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 33 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 34 | The efun raises a privilege violation ("net_connect", host, port). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 35 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 36 | BUGS |
| 37 | A non-blocking connect() doesn't imply a non-blocking |
| 38 | forward name resolution. If you provide a hostname instead |
| 39 | of an IP address to connect to, the driver will block until |
| 40 | the name is resolved. This may be an issue, depending on how |
| 41 | fast your nameserver replies. Non-blocking forward DNS |
| 42 | resolution can currently only be achieved using ERQ_LOOKUP. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 43 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 44 | HISTORY |
| 45 | First version 1992 by Snake and LynX for Nemesis. |
| 46 | Improved 1993 by Junky. |
| 47 | Added to LDMud 3.2.10. |
| 48 | |
| 49 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 50 | logon(A) |