File: xs.go

package info (click to toggle)
golang-github-farsightsec-go-nmsg 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 500 kB
  • sloc: sh: 21; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build libxs
// +build libxs

/*
 * Copyright (c) 2017 by Farsight Security, Inc.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package nmsg

/*
#cgo pkg-config: libnmsg libxs
#cgo LDFLAGS: -lnmsg -lxs
#include <stdlib.h>
#include <nmsg.h>
#include <xs/xs.h>
*/
import "C"
import "unsafe"

var xsContext unsafe.Pointer

func init() {
	xsContext = C.xs_init()
}

// NewXSInput opens an Input reading from the given XS endpoint.
func NewXSInput(xep string) Input {
	cxep := C.CString(xep)
	defer C.free(unsafe.Pointer(cxep))
	inp := C.nmsg_input_open_xs_endpoint(xsContext, cxep)
	if inp == nil {
		return nil
	}
	return &nmsgInput{input: inp}
}

// NewXSOutput creates an output writing to the given XS endpoint.
func NewXSOutput(xep string, bufsiz int) Output {
	cxep := C.CString(xep)
	defer C.free(unsafe.Pointer(cxep))
	outp := C.nmsg_output_open_xs_endpoint(xsContext, cxep, C.size_t(bufsiz))
	if outp == nil {
		return nil
	}
	return &nmsgOutput{output: outp}
}