Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic logic for g_socket #8

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CR fixes
  • Loading branch information
Nikita Vorontsov committed Apr 26, 2024
commit 0b56cb2f3c0658994f73220f1ddcfd61fe4f59eb
20 changes: 17 additions & 3 deletions glib/gsocket.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package glib

// #include <gio/gio.h>
import "C"
import (
"errors"
"syscall"
"unsafe"
)

func SocketNew(domain, typ, proto int) (*Object, error) {
type Socket struct {
ptr *Object
NoobsEnslaver marked this conversation as resolved.
Show resolved Hide resolved
}

func SocketNew(domain, typ, proto int) (*Socket, error) {
fd, err := syscall.Socket(domain, typ, proto)
if err != nil {
return nil, err
}
return SocketNewFromFd(fd)
}

func SocketNewFromFd(fd int) (*Object, error) {
func SocketNewFromFd(fd int) (*Socket, error) {
var gerr *C.GError
var socket *C.GSocket
socket = C.g_socket_new_from_fd((C.gint)(fd), (**C.GError)(unsafe.Pointer(&gerr)))
Expand All @@ -24,5 +29,14 @@ func SocketNewFromFd(fd int) (*Object, error) {
return nil, errors.New(C.GoString(gerr.message))
}

return Take(unsafe.Pointer(socket)), nil
return &Socket{ptr: Take(unsafe.Pointer(socket))}, nil
}

func (s *Socket) ToGValue() (*Value, error) {
val, err := ValueInit(TYPE_SOCKET)
if err != nil {
return nil, err
}
val.SetInstance(unsafe.Pointer(s.ptr.GObject))
return val, nil
}
2 changes: 1 addition & 1 deletion glib/gvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func gValue(v interface{}) (gvalue *Value, err error) {
return val, nil

case *Object:
val, err := ValueInit(e.TypeFromInstance())
val, err := ValueInit(TYPE_OBJECT)
if err != nil {
return nil, err
}
Expand Down