<commit_before>package main

/*
#cgo LDFLAGS: -L${SRCDIR}/../loaddlldemo -ldynsimpleipc

#include "simpleipc.h"

extern void callback(char* s);
*/
import "C"

import (
	"unsafe"
	"fmt"
	"time"
	"bufio"
	"os"
//	"syscall"
//	"log"
)

const (
	OPT_NO_THREAD = 0
	OPT_THREAD = 1
)

const SERVER_ID = "123"

var reader *bufio.Reader

// sleep for number of seconds
func sleepSec(sec time.Duration) {
	time.Sleep(sec * time.Second)
}

// sleep for number of milliseconds
func sleepMillisec(millisec time.Duration) {
	time.Sleep(millisec * time.Millisecond)
}

func Example1() {
	C.sIpcCreateServerTest()
	C.sIpcStartServer()
	// sleepMillisec(100)
	C.sIpcFreeServer()
}

var recvdstop bool = false

//export callback
func callback(s *C.char) {
	gostr := C.GoString(s)  // convert to golang string
	if gostr == "stop" {
		recvdstop = true
	}
	fmt.Println("Msg recvd: ", gostr)
}

func Example2() {
	cSERVER_ID := C.CString(SERVER_ID)  // convert to c string
	C.sIpcCreateServer(cSERVER_ID, OPT_NO_THREAD)
	C.sIpcStartServer()
	fmt.Println("IPC Server running")
    fmt.Println("Checking for messages...")
	for {
        C.sIpcExecOnMsg(10,10,(C.TCallbackString)(unsafe.Pointer(C.callback)),nil,nil,nil,nil)
        if recvdstop {
			break
		}
	}
	C.sIpcFreeServer()
}


func main() {
	reader = bufio.NewReader(os.Stdin)
	fmt.Println("Go program started")
	Example1()
	Example2()
	fmt.Println("Go program done")
}<commit_msg>multiple callback examples<commit_after>/* SimpleIPC demo server in go that uses the simple ipc dll
   Run the fpc client program to send a message to this go app
*/

package main

/*
#cgo LDFLAGS: -L${SRCDIR}/../loaddlldemo -ldynsimpleipc

#include "simpleipc.h"

// Go code linked up to these C names
extern void CallbackString(char* s);
extern void CallbackInt32(int i); 
// note: long vs int, vs int32.. fix this inconsistency
*/
import "C"

import (
	"unsafe"
	"fmt"
	"time"
	"bufio"
	"os"
//	"syscall"
//	"log"
)

const (
	OPT_NO_THREAD = 0
	OPT_THREAD = 1
)

const SERVER_ID = "123"

var reader *bufio.Reader

// sleep for number of seconds
func sleepSec(sec time.Duration) {
	time.Sleep(sec * time.Second)
}

// sleep for number of milliseconds
func sleepMillisec(millisec time.Duration) {
	time.Sleep(millisec * time.Millisecond)
}

func Example1() {
	C.sIpcCreateServerTest()
	C.sIpcStartServer()
	// sleepMillisec(100)
	C.sIpcFreeServer()
}

var recvdstop bool = false

//export CallbackString
func CallbackString(s *C.char) {
	gostr := C.GoString(s)  // convert to golang string
	if gostr == "stop" {
		recvdstop = true
	}
	fmt.Println("Msg recvd (string): ", gostr)
}

//export CallbackInt32
func CallbackInt32(i int32) {
	fmt.Println("Msg recvd (int32):  ", i)
}

func Example2() {
	cSERVER_ID := C.CString(SERVER_ID)  // convert to c string
	C.sIpcCreateServer(cSERVER_ID, OPT_NO_THREAD)
	C.sIpcStartServer()
	fmt.Println("IPC Server running")
    fmt.Println("Checking for messages...")
	for {
		// setup a callback when a msg is received
        C.sIpcExecOnMsg(10,10,
			(C.TCallbackString)(unsafe.Pointer(C.CallbackString)),  // one for a string message
			(C.TCallbackInt32)(unsafe.Pointer(C.CallbackInt32)), // one for an integer message
			nil,
			nil,
			nil)
        if recvdstop {
			break
		}
	}
	C.sIpcFreeServer()
}


func main() {
	reader = bufio.NewReader(os.Stdin)
	fmt.Println("Go program started")
	Example1()
	Example2()
	fmt.Println("Go program done")
}
{'fraction_non_alphanumeric': 0.1353493834409865, 'fraction_numerical': 0.014092777451556078, 'mean_word_length': 3.791842475386779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1645178', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1313, 'n_words': 315}