Hive
1 Network read and write
write/  flush
read/  timeout
2 Serializable objects
object
ref
find-by-ref
struct/  serialize
serializable?
serialize
deserialize
3 Users
users
8.12

Hive🔗ℹ

Roman Klochkov <kalimehtar@mail.ru>

Hive is the framework for a client-server application with persistent object storage on server side.

 (require hive/common) package: hive-common

This package provides functions, that will be used both on client and server sides of the hive application.

1 Network read and write🔗ℹ

 (require hive/common/read-write) package: hive-common

This library provides read and write for network streams. The connection is unreliable. I know, that TCP is considered reliable, but in fact, when network infrastucture drops part of packets, it may recover too slow. So, Hive uses keepalive packets and tools to control read timeout.

procedure

(write/flush data out)  void?

  data : any/c
  out : output-port?
Sends data to out and flushes out.

procedure

(read/timeout [in timeout])  any

  in : input-port? = (current-input-port)
  timeout : (or/c #f (and/c real? (not/c negative?)) (-> any))
   = 30
Reads from in like read. If read is not completed in timeout, returns eof. timeout is treated like in sync/timeout

2 Serializable objects🔗ℹ

 (require hive/common/serialize) package: hive-common

This library provide serializable objects. It differs from racket/serialize in that it doesn’t deep copy of the object. It rather replaces all field values, that references to other objects to special ref structure. This way the library may be used to send object by network or save to file without saving all linked objects.

struct

(struct object (id)
    #:extra-constructor-name make-object)
  id : exact-nonnegative-integer?
A structure type for objects, that may be used in serializable structure. Object types are expected to inherit this structure.

struct

(struct ref (typename id)
    #:extra-constructor-name make-ref)
  typename : symbol?
  id : exact-nonnegative-integer?
A structure type for references to objects. When object is serialize, all objects in its fields are replaced to refs.

procedure

(find-by-ref id objects)  (or/c #f object?)

  id : exact-nonnegative-integer?
  objects : (listof object?)
Returns an object with id equals to id from objects. If there is no such object, then returns #f.

Examples:
> (find-by-ref 2 (list (object 5) (object 6)))

#f

> (find-by-ref 5 (list (object 5) (object 6)))

#<object>

syntax

(struct/serialize name rest ...)

Constracts new serializable structure. Has same subforms as struct

procedure

(serializable? obj)  boolean?

  obj : any/c
Is a predicate for serializable objects.

procedure

(serialize obj [prepare])  list?

  obj : serializable?
  prepare : (serializable? . -> . serializable?) = identity
Returns serialization of the obj’s content. This serialization is for use with write and read. NB: it doesn’t contains type of obj. Type is expected to be known from other sources.

Examples:
> (struct/serialize test (a b) #:transparent)
> (define data (test (object 3) 5))
> (serialize data)

'(#s(ref object 3) 5)

procedure

(deserialize data deref)  any/c

  data : any/c
  deref : (ref? . -> . any/c)
Returns deserialized content of the serializable object. Result is expected be used to constract new object with same fields.

Examples:
> data

(test #<object> 5)

> (apply test (deserialize (serialize data)
                           (λ (r) (object (ref-id r)))))

(test #<object> 5)

3 Users🔗ℹ

 (require hive/common/users) package: hive-common

struct

(struct users object (name password role online)
    #:extra-constructor-name make-users
    #:mutable)
  name : string?
  password : string?
  role : symbol?
  online : #f
Represent user of Hive.
  • name - user name, any unicode characters allowed;

  • password - user password;

  • role - user role. Hive accepts 'admin and 'user, but application may invent it’s own;

  • online - #t, iff user is logged on and sending keepalive packets.