Skip to content

Commit 89131b7

Browse files
committed
Catch unknown host and expose isConnected property
1 parent 7dd9eeb commit 89131b7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/fbNetworkClient.bas

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ function fbNetworkClient.open(address as string, _port as uinteger, _protocol as
100100
end if
101101

102102
this._addressInfo = resolveHost(address, _port)
103+
if (this._addressInfo = 0) then
104+
this.onError(net_unknownHost)
105+
end if
106+
103107
this.setInfo(_port, _protocol, address)
104108
if (this.setSocket() = false) then
105109
mutexunlock(this._mutex)
@@ -109,6 +113,9 @@ function fbNetworkClient.open(address as string, _port as uinteger, _protocol as
109113
if( connect( this._socket, this._addressInfo->ai_addr, this._addressInfo->ai_addrlen ) = SOCKET_ERROR ) then
110114
closesocket( this._socket )
111115
freeaddrinfo(this._addressInfo)
116+
this._socket = 0
117+
this._addressInfo = 0
118+
112119
mutexunlock(this._mutex)
113120
this.onError(net_connectionRefused)
114121
return false
@@ -131,6 +138,9 @@ function fbNetworkClient.open(address as string, _port as uinteger, _protocol as
131138
return true
132139
end function
133140

141+
property fbNetworkClient.isConnected() as boolean
142+
return this._socket <> 0
143+
end property
134144

135145
property fbNetworkClient.host() as string
136146
return this.info.host

src/fbNetworkClient.bi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ end type
3535

3636
enum fbNetworkError
3737
net_undefined = 0
38-
net_timeout
39-
net_cantCreateSocket
40-
net_connectionInUse
41-
net_invalidPort
42-
net_connectionRefused
38+
net_timeout = 1
39+
net_cantCreateSocket = 2
40+
net_connectionInUse = 3
41+
net_invalidPort = 4
42+
net_connectionRefused = 5
43+
net_unknownHost = 6
4344
end enum
4445

4546
type fbNetworkClient extends object
@@ -62,6 +63,7 @@ type fbNetworkClient extends object
6263
declare property host() as string
6364
declare property ip() as string
6465
declare property port() as integer
66+
declare property isConnected() as boolean
6567

6668
declare abstract sub onConnect()
6769
declare abstract sub onClose()

0 commit comments

Comments
 (0)