Archived
3
0

Low-level changes for poll(2) version of the LibIPC.

This commit is contained in:
Karchnu 2020-07-01 16:24:13 +02:00
parent 485d26d677
commit 6f5aa676b5

View File

@ -2,16 +2,21 @@
@[Link("ipc")] @[Link("ipc")]
lib LibIPC lib LibIPC
struct Connection struct Connection
version : LibC::UInt
index : LibC::UInt
fd : LibC::Int
type : UInt8 type : UInt8
spath : LibC::Char* # [4096] # [PATH_MAX] spath : LibC::Char* # [4096] # [PATH_MAX]
end end
struct Connections struct Pollfd
cinfos : Connection** fd : LibC::Int
size : LibC::Int events : LibC::Short
revents : LibC::Short
end
struct Ctx
cinfos : Connection*
pollfd : Pollfd*
tx : Messages
size : LibC::UInt64
end end
struct Switching struct Switching
@ -31,11 +36,18 @@ lib LibIPC
LookUp LookUp
end end
# Messages are stored in lists within the libipc before being sent.
struct Messages
messages : Message*
size : LibC::UInt64
end
struct Message struct Message
type : UInt8 type : UInt8 # Internal message type.
user_type : UInt8 user_type : UInt8 # User-defined message type.
length : LibC::UInt fd : LibC::Int # fd of the sender.
payload : LibC::Char* length : LibC::UInt # Payload length.
payload : LibC::Char* #
end end
enum EventType enum EventType
@ -51,9 +63,10 @@ lib LibIPC
end end
struct Event struct Event
type : EventType type : EventType #
origin : Connection* index : LibC::UInt # Index of the sender in the ipc_ctx structure.
message : Message* origin : LibC::Int # fd of the sender.
message : Message* # Pointer to the reveiced message.
end end
struct IPCError struct IPCError
@ -62,36 +75,33 @@ lib LibIPC
error_message : LibC::Char[8192] error_message : LibC::Char[8192]
end end
fun ipc_server_init(env : LibC::Char**, connection : Connection*, sname : LibC::Char*) : IPCError # Connection functions.
fun ipc_server_close(Connection*) : IPCError # Context is allocated, ipcd is requested and the connection/initialisation is performed.
fun ipc_close(Connection*) : IPCError fun ipc_server_init(ctx : Ctx*, sname : LibC::Char*) : IPCError
fun ipc_connection(Ctx*, LibC::Char*) : IPCError
# connection to a service # Closing connections.
fun ipc_connection(LibC::Char**, Connection*, LibC::Char*) : IPCError fun ipc_close(ctx : Ctx*, index : LibC::UInt64) : IPCError
fun ipc_close_all(ctx : Ctx*) # Void
fun ipc_read(Connection*, Message*) : IPCError fun ipc_ctx_free(Ctx*) # Void
fun ipc_write(Connection*, Message*) : IPCError
fun ipc_wait_event(Connections*, Connection*, Event*, LibC::Double*) : IPCError # Loop function.
fun ipc_events_loop(Ctx*, Event*, LibC::UInt*) : IPCError
fun ipc_add(Connections*, Connection*) : IPCError # Adding and removing file discriptors to read.
fun ipc_del(Connections*, Connection*) : IPCError fun ipc_add(Ctx*, Connection*, Pollfd*) : IPCError
fun ipc_add_fd(Connections*, LibC::Int) : IPCError fun ipc_del(Ctx*, LibC::UInt) : IPCError
fun ipc_del_fd(Connections*, LibC::Int) : IPCError fun ipc_add_fd(Ctx*, LibC::Int) : IPCError
fun ipc_del_fd(Ctx*, LibC::Int) : IPCError
fun ipc_connection_gen(Connection*, LibC::UInt, LibC::UInt) : IPCError # Sending a message (will wait the fd to become available for IO operations).
fun ipc_write(Ctx*, Message*) : IPCError
fun ipc_connections_free(Connections*) # Void
fun ipc_connections_close(Connections*) # Void
# This function let the user get the default error message based on the error code. # This function let the user get the default error message based on the error code.
# The error message is contained in the IPCError structure, this function should not be used, in most cases. # The error message is contained in the IPCError structure, this function should not be used, in most cases.
fun ipc_errors_get (LibC::Int) : LibC::Char* fun ipc_errors_get (LibC::Int) : LibC::Char*
# networkd-related functions
fun ipc_wait_event_networkd(Connections*, Connection*, Event*, Switchings*, LibC::Double*) : IPCError
fun ipc_receive_fd (sock : LibC::Int, fd : LibC::Int*) : IPCError fun ipc_receive_fd (sock : LibC::Int, fd : LibC::Int*) : IPCError
fun ipc_provide_fd (sock : LibC::Int, fd : LibC::Int ) : IPCError fun ipc_provide_fd (sock : LibC::Int, fd : LibC::Int ) : IPCError
@ -100,7 +110,10 @@ lib LibIPC
fun ipc_switching_get (switch : Switchings*, fd : LibC::Int ) : LibC::Int fun ipc_switching_get (switch : Switchings*, fd : LibC::Int ) : LibC::Int
fun ipc_switching_free (switch : Switchings* ) # Void fun ipc_switching_free (switch : Switchings* ) # Void
# non public functions (for testing purposes) # non public functions
fun ipc_read(Ctx*, index : LibC::UInt, Message*) : IPCError
# for testing purposes
fun ipc_switching_print (switch : Switchings*) # Void fun ipc_switching_print (switch : Switchings*) # Void
fun service_path (path : LibC::Char*, sname : LibC::Char*, index : Int32, version : Int32) : IPCError fun service_path (path : LibC::Char*, sname : LibC::Char*, index : Int32, version : Int32) : IPCError
fun ipc_connections_print (Connections*) # Void fun ipc_connections_print (Connections*) # Void