Skip to content

Commit

Permalink
prepare for open source
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Osika committed Apr 11, 2023
1 parent 77d797c commit 70b3b55
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 19 deletions.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ simple rpc wrapper for a pvm3 wrapper in go
- `pvm` and `pvm-dev` installed on your system
- the paths set up correctly for pvm
- `go`, `gcc`, etc

## usage
see `demo.go`
10 changes: 8 additions & 2 deletions pvm_rpc/client.go → client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"math"
"math/rand"
"pvm_rpc/pvm"
"time"

"github.com/kxait/pvm-rpc/pvm"
)

func Sus() {}
Expand Down Expand Up @@ -52,7 +53,7 @@ func (t *Target) Call(msgType MessageType, content string) <-chan *ReceiveResult
result := <-t.receiveContinuously(msg.Id)

if result.Err != nil {
r <- &ReceiveResult{Err: err}
r <- &ReceiveResult{Err: result.Err}
return
}

Expand Down Expand Up @@ -125,6 +126,11 @@ func (t *Target) receiveContinuously(id int) <-chan *ReceiveResult {
break
}

if deserialized.IsError {
r <- &ReceiveResult{Err: fmt.Errorf(deserialized.Content)}
break
}

r <- &ReceiveResult{Response: deserialized}
break
}
Expand Down
File renamed without changes.
20 changes: 13 additions & 7 deletions main.go → demo.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package main
package pvm_rpc

import (
"fmt"
"os"
"pvm_rpc/pvm"
"pvm_rpc/pvm_rpc"
"time"

"github.com/kxait/pvm-rpc/pvm"
)

func main() {
if len(os.Args) < 2 {
panic(":(")
}
pvm.Initsend(pvm.DataDefault)
_, err := pvm.Initsend(pvm.DataDefault)

if err != nil {
println("pvm.Initsend (pvm_initsend()) failed. this might indicate that you do not have pvm on your system or it is not running.")
panic(err)
}

mode := os.Args[1]
if mode == "client" {
Expand All @@ -26,7 +31,7 @@ func main() {
panic(err)
}

target := pvm_rpc.Target{TaskId: parentId}
target := Target{TaskId: parentId}

for {
time.Sleep(1 * time.Millisecond)
Expand All @@ -50,8 +55,8 @@ func main() {

fmt.Printf("child spawned with id %d\n", result.TIds[0])

server := pvm_rpc.RpcServer{Handlers: make(map[pvm_rpc.MessageType]pvm_rpc.RpcHandler)}
server.Handlers["ping"] = func(m *pvm_rpc.Message) (*pvm_rpc.Message, error) {
server := RpcServer{Handlers: make(map[MessageType]RpcHandler)}
server.Handlers["ping"] = func(m *Message) (*Message, error) {
fmt.Printf("%s\n", m.Content)
return m.CreateResponse("pong"), nil
}
Expand All @@ -65,5 +70,6 @@ func main() {
}
fmt.Printf("server stopped working: %s\n", erro)
} else {
panic(":(")
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module pvm_rpc
module github.com/kxait/pvm-rpc

go 1.20
File renamed without changes.
8 changes: 4 additions & 4 deletions pvm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package pvm

import "fmt"

/*
* Data packing styles for pvm_initsend()
*/

const DEBUG = false

func dbgln(frmt string, args ...any) {
Expand All @@ -14,6 +10,10 @@ func dbgln(frmt string, args ...any) {
}
}

/*
* Data packing styles for pvm_initsend()
*/

type DataPackingStyle int64

const (
Expand Down
3 changes: 2 additions & 1 deletion pvm_rpc/server.go → server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package pvm_rpc
import (
"encoding/json"
"fmt"
"pvm_rpc/pvm"

"github.com/kxait/pvm-rpc/pvm"
)

func (rs *RpcServer) StepEventLoop() error {
Expand Down
5 changes: 1 addition & 4 deletions pvm_rpc/types.go → types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type Target struct {

func NewTarget(taskId int) *Target {
targ := Target{TaskId: taskId}
//targ.ResetSendBuffer()

return &targ
}
Expand All @@ -18,9 +17,7 @@ type ReceiveResult struct {

type MessageType string
type Message struct {
// IMPORTANT: Generated randomly by the caller
Id int
// Will not change on response (will be client tId)
Id int
CallerTaskId int
Type MessageType
Content string
Expand Down

0 comments on commit 70b3b55

Please sign in to comment.