Code Monkey home page Code Monkey logo

Comments (10)

ghettovoice avatar ghettovoice commented on May 18, 2024 1

Hello @YiuTerran ,
probably I can append tp protocol auto-intialization also in the Send message... And I hope it will not break anything.
This change should allow sending SIP requests without listeners setup, but sure will correctly work only with reliable transports

from gosip.

YiuTerran avatar YiuTerran commented on May 18, 2024

I just use a mock Listener for my purpose:

type Listener struct {
	network string
	addr    net.Addr
	ch      chan net.Conn
}

func ListenTCP(network string, addr *net.TCPAddr) (net.Listener, error) {
	return &Listener{
		network: network,
		addr:    addr,
		ch:      make(chan net.Conn, 1),
	}, nil
}

// Accept never return
func (l Listener) Accept() (net.Conn, error) {
	return <-l.ch, io.EOF
}

func (l Listener) Close() error {
	defer func() {
		if i := recover(); i != nil {
			//just ignore
		}
	}()
        close(l.ch)
	return nil
}

func (l Listener) Addr() net.Addr {
	return l.addr
}

from gosip.

ghettovoice avatar ghettovoice commented on May 18, 2024

@YiuTerran I have pushed a patch to the dev branch. Can you try it in your app/env?
You can install it with go get github.com/ghettovoice/gosip@dev

from gosip.

YiuTerran avatar YiuTerran commented on May 18, 2024

@YiuTerran I have pushed a patch to the dev branch. Can you try it in your app/env? You can install it with go get github.com/ghettovoice/gosip@dev

ok, i will try it next week. thanks very much~

from gosip.

YiuTerran avatar YiuTerran commented on May 18, 2024

Sorry for late reply. I just test the dev branch, it looks that everything is fine without listening any port when using TCP.

Thanks for your help~

from gosip.

YiuTerran avatar YiuTerran commented on May 18, 2024

@ghettovoice But i just review the code, found a little problem:

func (tpl *layer) getProtocol(network string) (p Protocol, err error) {
	var ok bool
       // not goroutine safe, we need some func like `LoadOrStore` here
	p, ok = tpl.protocols.get(protocolKey(network))
	if ok {
		return
	}
	p, err = protocolFactory(
		network,
		tpl.pmsgs,
		tpl.perrs,
		tpl.canceled,
		tpl.msgMapper,
		tpl.Log(),
	)
	if err != nil {
		return nil, err
	}
	tpl.protocols.put(protocolKey(p.Network()), p)
	return p, nil
}

from gosip.

ghettovoice avatar ghettovoice commented on May 18, 2024

tpl.protocols points to internal map+mutex store

from gosip.

YiuTerran avatar YiuTerran commented on May 18, 2024

tpl.protocols points to internal map+mutex store

Yeah, but data race happens between get and put. It's not a big problem.

from gosip.

ghettovoice avatar ghettovoice commented on May 18, 2024

Ah, I see now. Do you talking about that get and put should be made as single "atomic" action?

from gosip.

YiuTerran avatar YiuTerran commented on May 18, 2024

Ah, I see now. Do you talking about that get and put should be made as single "atomic" action?

Yeah, maybe it's betterπŸ˜ƒ

from gosip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.