logind
---


Design:
---

imap.h:
- IMAP command definitions


file_io.{h|cc}:
- class fio_handler:
  - derived from io_handler
  - instantiated on initialization
  - passed the read end of a pipe and the write end of another pipe
  - sets both fds to non-blocking and requests notification on read
    availability for the incoming pipe
  - provides an interface function for a request to be sent to a
    fio_thread (by a session); prepares a request packet which also
    contains requester info and sends it on the outgoing pipe
  - when notified of available input on the incoming pipe, reads in
    the response to a request which contains the requester's info;
    passes the response on to the requester

- class fio_thread:
  - instantiated on initialization using threaded<>
  - passed the other ends of the two pipes given to a fio_handler
  - blocks on read()
  - processes a request: a file i/o related IMAP command; currently
    only LOGIN and LIST
  - responds by writing to the outgoing pipe


logind.{h|cc}:
- main(): calls server.run()
- class logind:
  - a single global instance called 'server' is created
  - run():
    - parses command line arguments
    - creates event loop
    - creates terminal (no commands added)
    - sets n = max_fds / 16
    - creates n * 2 pipes
    - n file i/o threads (block freely)
    - n file i/o handlers (non-blocking, part of io_event_loop)
    - each thread/handler pair gets two pipes for bi-directional
      communication
    - creates a tcp_acceptor, giving it 'session'
    - starts the event loop
  - get_fioh():
      - called from a session which needs a file i/o request served;
        returns a file i/o handler (round-robin over all)


session.{h|cc}:
- class session:
  - one instantiated for each incoming connection by tcp_acceptor
  - incoming_data() parses and processes incoming IMAP commands
  - stores authentication state and responds correctly
  - on receiving commands which require file i/o (LOGIN and LIST),
    requests a fio_handler from the global server and requests the
    operation from the handler
  - receives the result in fio_response() (invoked by fio_handler())
    and responds to the client
  - destroyed when the connection is closed or on LOGOUT



Assumptions and Limitations:
---

- a pipe can have one of its fds be blocking and the other non-blocking
  (appears to be true)

- complete wildcard expansion on LIST's mailbox name parameter is not
  yet implemented; the following will work, however:
  001 LIST "" *
  002 LIST "" foo/*
  003 LIST foo *
  004 LIST foo bar

- a port number lower than 1024 cannot be specified (when this is
  allowed and you aren't root, tcp_acceptor<> silently dies); this can
  be changed in logind.cc:63


