haskell - Is there a way to convert an IO handle to a socket? -


I'm messing with networking in Haskell, and before trying to connect before adding time, try to connect how long.

Unfortunately, returns a handle to the connect, in which there are no changeable timeout criteria. Does anyone know by any means that to get a socket from a handle by notation?

Thanks

Running from the socket handle to the lower level By looking at the source of the network package, I can come in the following ways to modify the time of use of the handle:

  Import the appropriate control. Exception Import Data.Int (Int64) Import Network Import Network as Opportunity. BSD importable network socket socket as socket (accept) import network. Import the Socket Socket (Accept, SocketPorte, Requelfrom, Sendentu, PortNumber, Clock) Import Network.Socket.Options (setSendTimeout) system. IO Type MicroSecond = Int64 myconnectTo :: Hostname - Hostname - & gt; PortID - Port Identifier - & gt; Microsecond - & gt; IO handles - Connected socket myconnectTo host name (service all) T = proto & lt do, - getProtocolNumber "TCP" bracketOnError (socket AF_INET stream proto & gt; & gt; = \ x - & gt; setSendTimeout xt & gt; & gt; return x) (sClose) - though there is an error, (\ sock - & gt; the port & lt, - getServicePortNumber all that & lt; - gethostbyname hostname sock (SockAddrInet port (connected hostAddress she)) SocketToHandle sock ReadWriteMode) tend to myconnectTo hostname (portnumber port) t = proto & lt, - getProtocolNumber "T CP "bracketOnError (socket AF_INET stream proto & gt; & gt; = \ x - & gt; setSendTimeout xt & gt; & gt; return x) (sClose) - though there is an error, (\ sock - & gt he is & lt, - gethostbyname host name to connect sock (SockAddrInet port (hostAddress she)) socketToHandle sock ReadWriteMode) bracketOnError = Exception.bracketOnError   

note that I did not really Code is tested, but check it type It should be noted that it only works for IPv4 systems Defense but it is easily adaptable to IPv6 package. I use the function from the network option package to manipulate timeouts.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -