raiguard/odin-wayland
git clone https://git.raiguard.me/raiguard/odin-wayland
fd8ef50
trunk
1#+build linux 2#+vet explicit-allocators 3package wayland 4 5import "core:log" 6import "core:io" 7import "core:sys/linux" 8 9// ===================================================================================================================== 10// SOCKET BOILERPLATE 11 12_unix_socket_read :: proc ( stream_data : rawptr , mode : io . Stream_Mode , buffer : [] u8 , offset : i64 , whence : io . Seek_From ) -> ( n : i64 , error : io . Error ) { 13assert ( mode == . Read ) 14session := cast ( ^ Session ) stream_data 15 16// TODO: non-blocking mode 17n_read , errno := linux . read ( session . socket_data . fd , buffer ) 18if errno != . NONE { 19log . errorf ( "linux.read failed with" , errno ) 20} 21 22if session . debug_logging_enabled { 23log . debug ( n_read , buffer [: n_read ]) 24} 25 26return i64 ( n_read ), errno != . NONE ? . Unknown : nil 27} 28 29_unix_socket_write :: proc ( stream_data : rawptr , mode : io . Stream_Mode , buffer : [] u8 , offset : i64 , whence : io . Seek_From ) -> ( n : i64 , error : io . Error ) { 30assert ( mode == . Write ) 31session := cast ( ^ Session ) stream_data 32 33if session . debug_logging_enabled { 34log . debug ( len ( buffer ), buffer ) 35} 36 37n_written , errno := linux . write ( session . socket_data . fd , buffer ) 38if errno != . NONE { 39log . errorf ( "linux.write failed with" , errno ) 40} 41return i64 ( n_written ), errno != . NONE ? . Unknown : nil 42}