Giter Site home page Giter Site logo

z-io's Introduction

Z-IO

Hackage Linux Build Status MacOS Build Status Windows Build Status Docker Build Status Gitter chat

This package is part of Z.Haskell project, provides basic IO operations:

  • IO resource management, resource pool
  • File system operations
  • Network: DNS, TCP, UDP and IPC
  • Buffered input and output
  • Process management
  • Environment settings
  • High performance logger
  • High performance low resolution timer

Requirements

  • A working haskell compiler system, GHC(>=8.6), cabal-install(>=2.4), hsc2hs.
  • Tests need hspec-discover.

Example usage

> :set -XOverloadedStrings
> import Z.IO.Network
> import Z.IO.Resource
> import Z.IO.Buffered
>
> -- call getAddrInfo to perform DNS
> head <$> getAddrInfo Nothing "www.bing.com" "http"
AddrInfo {addrFlags = [AI_ADDRCONFIG,AI_V4MAPPED], addrFamily = SocketFamily 2, addrSocketType = SocketType 1, addrProtocol = ProtocolNumber 6, addrAddress = 204.79.197.200:80, addrCanonName = ""}
>
> import qualified Z.Data.Text as T
> -- send a simple HTTP request
> :{
let addr = ipv4 "13.107.21.200" 80
in withResource (initTCPClient defaultTCPClientConfig{ tcpRemoteAddr = addr}) $ \ tcp -> do
    (i, o) <- newBufferedIO tcp
    writeBuffer' o "GET http://www.bing.com HTTP/1.1\r\nHost: www.bing.com\r\n\r\n"
    readBuffer i >>= pure . T.validate
:}
"HTTP/1.1 200 OK\r\nDate: Sat, 19 Sep 2020 06:11:08 GMT\r\nContent-Length: 0\r\n\r\n"
>
> -- Start a TCP echo server, use @nc -v localhost 8080@ to test
> :{
startTCPServer defaultTCPServerConfig{
    tcpListenAddr = SocketAddrIPv4 ipv4Loopback 8080} $ \ tcp -> do
        i <- newBufferedInput tcp
        o <- newBufferedOutput tcp
        forever $ readBuffer i >>= writeBuffer o >> flushBuffer o
}
:}

Dev guide

# get code
git clone --recursive [email protected]:ZHaskell/z-io.git
cd z-io
# build
cabal build
# test
cabal run Z-IO-Test
# install
cabal install
# generate document
cabal haddock

z-io's People

Contributors

4euep avatar alissa-tung avatar winterland1989 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.