mirror of
https://codeberg.org/scip/swayipc.git
synced 2026-08-23 22:34:20 +02:00
renovate the code, update to go 1.26 and satisfy linter (#3)
This commit is contained in:
16
net.go
16
net.go
@@ -8,7 +8,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// Contains a raw json response, not marshalled yet.
|
||||
// RawResponse contains a raw json response, not marshalled yet.
|
||||
type RawResponse struct {
|
||||
PayloadType int
|
||||
Payload []byte
|
||||
@@ -39,14 +39,13 @@ func (ipc *SwayIPC) Close() error {
|
||||
}
|
||||
|
||||
func (ipc *SwayIPC) sendHeader(messageType uint32, len uint32) error {
|
||||
sendPayload := make([]byte, IPC_HEADER_SIZE)
|
||||
sendPayload := make([]byte, IpcHeaderSize)
|
||||
|
||||
copy(sendPayload, []byte(IPC_MAGIC))
|
||||
binary.LittleEndian.PutUint32(sendPayload[IPC_MAGIC_LEN:], len)
|
||||
binary.LittleEndian.PutUint32(sendPayload[IPC_MAGIC_LEN+4:], messageType)
|
||||
copy(sendPayload, []byte(IpcMagix))
|
||||
binary.LittleEndian.PutUint32(sendPayload[IpcMagicLen:], len)
|
||||
binary.LittleEndian.PutUint32(sendPayload[IpcMagicLen+4:], messageType)
|
||||
|
||||
_, err := ipc.socket.Write(sendPayload)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send header to IPC socket %w", err)
|
||||
}
|
||||
@@ -56,7 +55,6 @@ func (ipc *SwayIPC) sendHeader(messageType uint32, len uint32) error {
|
||||
|
||||
func (ipc *SwayIPC) sendPayload(payload []byte) error {
|
||||
_, err := ipc.socket.Write(payload)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send payload to IPC socket %w", err)
|
||||
}
|
||||
@@ -66,14 +64,14 @@ func (ipc *SwayIPC) sendPayload(payload []byte) error {
|
||||
|
||||
func (ipc *SwayIPC) readResponse() (*RawResponse, error) {
|
||||
// read header
|
||||
buf := make([]byte, IPC_HEADER_SIZE)
|
||||
buf := make([]byte, IpcHeaderSize)
|
||||
|
||||
_, err := ipc.socket.Read(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read header from ipc socket: %s", err)
|
||||
}
|
||||
|
||||
if string(buf[:6]) != IPC_MAGIC {
|
||||
if string(buf[:6]) != IpcMagix {
|
||||
return nil, errors.New("got invalid response from IPC socket")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user