RefuseConnection - listener will refuse connections after connections amount overflow;

IncreaseConnection - listener will start yet another 50 acceptors.

Accnb - number of acceptors;

Port - connection port;

Handler - function with 2 parameters: input string and conn tcp.Connection. It will calls when client send something to server ;

and ; Lc - listener channel, it needs for communicating with listener;

OverFlowStrategy - It can be 0 || 1, see note about overflow strategies;

Ssl - it is a map, we need to use it if we want to use ssl. Just create map with 2 string keys: pam and key. Next if will show how to use it.

Connection.Close - close current connection;

Connection.Send - send response.

connectionCounter - channel for communicating between acceptor goroutines and listener. If connection was closed it sends message to listener and listener decrease connection numbers, if new connection was accepted it increase connection number;

closeConnection - channel for commuicating between listener and acceptor for closing current connection.

very pleased to hear it, write me in comment or ping me in twitter

netpool/tcp

netpool/tcp example of usage

So, as maybe some of you knows that i have started to use Golang programming language for my pet projects and since to solve "Project Euler" tasks is very useful deal, but very boring in the same time, i decided to create something more closer to real life. I decided to write XMPP server in golang and in this post i will tell about one part of this server - netpool/tcp library. netpool/tcp - is a tcp based socket acceptor pool. The idea is very simple, you will launch TCP listener which will launch many acceptors besides one, in this way you no need to spend time for creating new connection acceptor.First of all let's create newpackage and import all libraries which will we need in this project:Now let's define types which we will need in our acceptor pool:Let's go by order. First enumeration defines strategies when connection listener handles more connections than we define.Next is simpe constant value which defines how many acceptors need to start after connections amount overflow.Next isstructure. It is a main structure which we will pass tofunction for launching new listener. It has following fields:Also it has API which consists now only from one function -without any arguments, you can stop current connection with it.Next is astructure. We have it every time as second parameter in connection handler function. It has simple API for manipulating with connection:So, now web have all types which we will use in this library. Now proceed to implementation. All API ofconsists only from one function:It's a main function of this library and it launches new tcp listener and some acceptors. Let's see how it implemented.First of all it defines some variables like:for count acceptors, checks is it connection over SSL or not and launches listener which depends on this:Next it creates 2 channels:and starts acceptors:After this listener waits for messages from another goroutines for closing current listener, closing connection, connection removed/created and etc...:So what about acceptors... It's pretty simple as a listener implementation, it starts from accepting new connection and waits for incoming messages from connected client. If there are any incoming data from client it callfunction and pass input data andstructure to it:After this it as a listener checks incoming message from other goroutines, to stop connection and etc...So it's end. As we can saw concurrency is a pretty simple with Golang.As i said in previous post i'm not a golang super-hacker, if you will have any recommendations for my golang code or you want to take part in XMPP server developing with golang i will be. Also i made this library primarily for future extd XMPP server but i tried to make it generic so i think it can be useful not only for me.