AppliedGo / comments

Utteranc.es comments for appliedgo.net
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

networking #8

Open christophberger opened 1 year ago

christophberger commented 1 year ago

Written on 02/25/2017 14:50:35

URL: https://appliedgo.net/networking/

christophberger commented 1 year ago

Migrated comment, written by Povilas Versockas on 03/14/2017 07:12:36

Hey,

Great post! I really like that you used gob package.

There is a little mistake in Step 2, it should be "cd $GOPATH/src/github.com/appliedgo/networ..." not "cd $GOPATH/github.com/appliedgo/networ...".

christophberger commented 1 year ago

Migrated comment, written by Christoph on 03/14/2017 08:25:06

Thanks for letting me know! I fixed it.

christophberger commented 1 year ago

Migrated comment, written by 独行的蚂蚁 on 12/08/2017 03:59:18

Your blog looks nice, thank you for the article.

christophberger commented 1 year ago

Migrated comment, written by gxvrtplkfdawr gxvrtplkfdawr on 05/04/2018 16:03:38

return errors.Wrap(err, "Unable to listen on "+e.listener.Addr().String()+"\n") - on this line will be runtime error because listener is nil.

christophberger commented 1 year ago

Migrated comment, written by Christoph on 05/07/2018 19:45:55

You are right - this would work if listener was a struct, but here, listener is an interface, and a nil interface contains no implemented methods. I will update the article as soon as i will have sorted out an issue with my blog post generator code.

christophberger commented 1 year ago

Migrated comment, written by gxvrtplkfdawr gxvrtplkfdawr on 05/16/2018 20:45:52

Hmmm, why we need lock here, AddHandleFunc is not concurrently?
e.m.Lock()
e.handler[name] = f
e.m.Unlock()

And why we need lock here?
e.m.RLock()
handleCommand, ok := e.handler[cmd]
e.m.RUnlock()
It is just read?

christophberger commented 1 year ago

Migrated comment, written by Christoph on 05/20/2018 17:05:38

Indeed, AddHandlerFunc is not called in a concurrent way in this code (that is, there are no other goroutines running at that point that would also access the map). But if you would take the unprotected call and use it in a context where concurrent code is already executing, then the mutex is necessary.

Regarding the lock when reading e.handler[cmd], this is only a read lock. Multiple readers can hold a read lock at the same time, so they do not block each other. However, a writer that requests a write lock has to wait until no more read locks are active.

christophberger commented 1 year ago

Migrated comment, written by youmoo on 05/07/2019 04:42:19

Very easy to understand. Can I translate this article to Chinese? I will provide the original link to this article. Thanks