gi-soup-2.4.14: Libsoup bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.Soup.Objects.Socket

Contents

Description

 

Synopsis

Exported types

toSocket :: (MonadIO m, IsSocket o) => o -> m Socket Source #

Methods

connectAsync

socketConnectAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: a client Socket (which must not already be connected)

-> Maybe b

cancellable: a Cancellable, or Nothing

-> SocketCallback

callback: callback to call after connecting

-> m () 

Begins asynchronously connecting to sock's remote address. The socket will call callback when it succeeds or fails (but not before returning from this function).

If cancellable is non-Nothing, it can be used to cancel the connection. callback will still be invoked in this case, with a status of StatusCancelled.

connectSync

socketConnectSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: a client Socket (which must not already be connected)

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m Word32

Returns: a success or failure code.

Attempt to synchronously connect sock to its remote address.

If cancellable is non-Nothing, it can be used to cancel the connection, in which case socketConnectSync will return StatusCancelled.

disconnect

socketDisconnect Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m () 

Disconnects sock. Any further read or write attempts on it will fail.

getFd

socketGetFd Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Int32

Returns: sock's file descriptor.

Gets sock's underlying file descriptor.

Note that fiddling with the file descriptor may break the Socket.

getLocalAddress

socketGetLocalAddress Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Address

Returns: the Address

Returns the Address corresponding to the local end of sock.

Calling this method on an unconnected socket is considered to be an error, and produces undefined results.

getRemoteAddress

socketGetRemoteAddress Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Address

Returns: the Address

Returns the Address corresponding to the remote end of sock.

Calling this method on an unconnected socket is considered to be an error, and produces undefined results.

isConnected

socketIsConnected Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Bool

Returns: True or False.

Tests if sock is connected to another host

isSsl

socketIsSsl Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a Socket

-> m Bool

Returns: True if sock has SSL credentials set

Tests if sock is doing (or has attempted to do) SSL.

listen

socketListen Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

sock: a server Socket (which must not already be connected or listening)

-> m Bool

Returns: whether or not sock is now listening.

Makes sock start listening on its local address. When connections come in, sock will emit Socket::new_connection.

read

socketRead Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> ByteString

buffer: buffer to read into

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m (SocketIOStatus, Word64)

Returns: a SocketIOStatus, as described above (or SocketIOStatusEof if the socket is no longer connected, or SocketIOStatusError on any other error, in which case error will also be set). (Can throw GError)

Attempts to read up to len bytes from sock into buffer. If some data is successfully read, socketRead will return SocketIOStatusOk, and *nread will contain the number of bytes actually read (which may be less than len).

If sock is non-blocking, and no data is available, the return value will be SocketIOStatusWouldBlock. In this case, the caller can connect to the Socket::readable signal to know when there is more data to read. (NB: You MUST read all available data off the socket first. Socket::readable is only emitted after socketRead returns SocketIOStatusWouldBlock, and it is only emitted once. See the documentation for Socket:non-blocking.)

readUntil

socketReadUntil Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> ByteString

buffer: buffer to read into

-> Ptr ()

boundary: boundary to read until

-> Word64

boundaryLen: length of boundary in bytes

-> Bool

gotBoundary: on return, whether or not the data in buffer ends with the boundary string

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m (SocketIOStatus, Word64)

Returns: as for socketRead (Can throw GError)

Like socketRead, but reads no further than the first occurrence of boundary. (If the boundary is found, it will be included in the returned data, and *gotBoundary will be set to True.) Any data after the boundary will returned in future reads.

socketReadUntil will almost always return fewer than len bytes: if the boundary is found, then it will only return the bytes up until the end of the boundary, and if the boundary is not found, then it will leave the last <literal>(boundary_len - 1)</literal> bytes in its internal buffer, in case they form the start of the boundary string. Thus, len normally needs to be at least 1 byte longer than boundaryLen if you want to make any progress at all.

startProxySsl

socketStartProxySsl Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> Text

sslHost: hostname of the SSL server

-> Maybe b

cancellable: a Cancellable

-> m Bool

Returns: success or failure

Starts using SSL on socket, expecting to find a host named sslHost.

startSsl

socketStartSsl Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> Maybe b

cancellable: a Cancellable

-> m Bool

Returns: success or failure

Starts using SSL on socket.

write

socketWrite Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a, IsCancellable b) 
=> a

sock: the socket

-> ByteString

buffer: data to write

-> Maybe b

cancellable: a Cancellable, or Nothing

-> m (SocketIOStatus, Word64)

Returns: a SocketIOStatus, as described above (or SocketIOStatusEof or SocketIOStatusError. error will be set if the return value is SocketIOStatusError.) (Can throw GError)

Attempts to write len bytes from buffer to sock. If some data is successfully written, the return status will be SocketIOStatusOk, and *nwrote will contain the number of bytes actually written (which may be less than len).

If sock is non-blocking, and no data could be written right away, the return value will be SocketIOStatusWouldBlock. In this case, the caller can connect to the Socket::writable signal to know when more data can be written. (NB: Socket::writable is only emitted after socketWrite returns SocketIOStatusWouldBlock, and it is only emitted once. See the documentation for Socket:non-blocking.)

Properties

asyncContext

fd

gsocket

iostream

ipv6Only

setSocketIpv6Only :: (MonadIO m, IsSocket o) => o -> Bool -> m () Source #

isServer

localAddress

nonBlocking

setSocketNonBlocking :: (MonadIO m, IsSocket o) => o -> Bool -> m () Source #

remoteAddress

sslCreds

getSocketSslCreds :: (MonadIO m, IsSocket o) => o -> m (Ptr ()) Source #

setSocketSslCreds :: (MonadIO m, IsSocket o) => o -> Ptr () -> m () Source #

sslFallback

sslStrict

timeout

setSocketTimeout :: (MonadIO m, IsSocket o) => o -> Word32 -> m () Source #

tlsCertificate

tlsErrors

trustedCertificate

useThreadContext

Signals

disconnected

event

type C_SocketEventCallback = Ptr () -> CUInt -> Ptr IOStream -> Ptr () -> IO () Source #

newConnection

readable

type C_SocketReadableCallback = Ptr () -> Ptr () -> IO () Source #

writable

type C_SocketWritableCallback = Ptr () -> Ptr () -> IO () Source #