diff --git a/README.md b/README.md index cbd40d8..2b226f2 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ func main() { // route all requests to a single php file http.Handle("/", gofast.NewHandler( gofast.NewFileEndpoint("/var/www/html/index.php")(gofast.BasicSession), - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), )) // serve at 8080 port @@ -153,7 +153,7 @@ func main() { // route all requests to relevant PHP file http.Handle("/", gofast.NewHandler( gofast.NewPHPFS("/var/www/html")(gofast.BasicSession), - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), )) // serve at 8080 port @@ -229,7 +229,7 @@ func main() { // route all requests to a single php file http.Handle("/", gofast.NewHandler( gofast.NewFileEndpoint("/var/www/html/index.php")(sess), - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), )) // serve at 8080 port @@ -308,7 +308,7 @@ func myApp() http.Handler { func main() { address := os.Getenv("FASTCGI_ADDR") connFactory := gofast.SimpleConnFactory("tcp", address) - clientFactory := gofast.SimpleClientFactory(connFactory, 0) + clientFactory := gofast.SimpleClientFactory(connFactory) // authorization with php authSess := gofast.Chain( @@ -361,7 +361,7 @@ import ( func main() { address := os.Getenv("FASTCGI_ADDR") connFactory := gofast.SimpleConnFactory("tcp", address) - clientFactory := gofast.SimpleClientFactory(connFactory, 0) + clientFactory := gofast.SimpleClientFactory(connFactory) // Note: The local file system "/var/www/html/" only need to be // local to web server. No need for the FastCGI application to access @@ -420,7 +420,7 @@ func main() { // handle all scripts in document root // extra pooling layer pool := gofast.NewClientPool( - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), 10, // buffer size for pre-created client-connection 30*time.Second, // life span of a client before expire ) diff --git a/client.go b/client.go index b7e9635..862a138 100644 --- a/client.go +++ b/client.go @@ -386,10 +386,7 @@ type ClientFactory func() (Client, error) // SimpleClientFactory returns a ClientFactory implementation // with the given ConnFactory. -// -// limit is UNUSED. -// -func SimpleClientFactory(connFactory ConnFactory, limit uint32) ClientFactory { +func SimpleClientFactory(connFactory ConnFactory) ClientFactory { return func() (c Client, err error) { // connect to given network address conn, err := connFactory() diff --git a/client_test.go b/client_test.go index c70296a..04e6106 100644 --- a/client_test.go +++ b/client_test.go @@ -109,7 +109,6 @@ func testHandlerForCancel(t *testing.T, p *appServer, w http.ResponseWriter, r * c, err := gofast.SimpleClientFactory( gofast.SimpleConnFactory(p.Network(), p.Address()), - 0, )() if err != nil { http.Error(w, "failed to connect to FastCGI application", http.StatusBadGateway) @@ -203,7 +202,6 @@ func TestClient_StdErr(t *testing.T) { doRequest := func(w http.ResponseWriter, r *http.Request) (errStr string) { c, err := gofast.SimpleClientFactory( gofast.SimpleConnFactory(p.Network(), p.Address()), - 0, )() if err != nil { errStr = "web server: unable to connect to FastCGI application: " + err.Error() diff --git a/example/nodejs/nodejs.go b/example/nodejs/nodejs.go index 5e0f57b..36a38f4 100644 --- a/example/nodejs/nodejs.go +++ b/example/nodejs/nodejs.go @@ -20,7 +20,7 @@ import ( func NewHandler(entrypoint, network, address string) http.Handler { connFactory := gofast.SimpleConnFactory(network, address) pool := gofast.NewClientPool( - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), 10, 60*time.Second, ) @@ -59,7 +59,7 @@ func NewMuxHandler( // common client pool for both filter and responder handler connFactory := gofast.SimpleConnFactory(network, address) pool := gofast.NewClientPool( - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), 10, 60*time.Second, ) diff --git a/example/php/php.go b/example/php/php.go index 2648b2f..04e9842 100644 --- a/example/php/php.go +++ b/example/php/php.go @@ -21,7 +21,7 @@ func NewSimpleHandler(docroot, network, address string) http.Handler { connFactory := gofast.SimpleConnFactory(network, address) h := gofast.NewHandler( gofast.NewPHPFS(docroot)(gofast.BasicSession), - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), ) return h } @@ -41,7 +41,7 @@ func NewFileEndpointHandler(filepath, network, address string) http.Handler { connFactory := gofast.SimpleConnFactory(network, address) h := gofast.NewHandler( gofast.NewFileEndpoint(filepath)(gofast.BasicSession), - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), ) return h } diff --git a/example/python3/python3.go b/example/python3/python3.go index aca86f5..f714d8e 100644 --- a/example/python3/python3.go +++ b/example/python3/python3.go @@ -20,7 +20,7 @@ import ( func NewHandler(entrypoint, network, address string) http.Handler { connFactory := gofast.SimpleConnFactory(network, address) pool := gofast.NewClientPool( - gofast.SimpleClientFactory(connFactory, 0), + gofast.SimpleClientFactory(connFactory), 10, 60*time.Second, ) diff --git a/host_test.go b/host_test.go index d66c774..d0682bd 100644 --- a/host_test.go +++ b/host_test.go @@ -45,7 +45,6 @@ func TestHandler(t *testing.T) { l.Addr().Network(), l.Addr().String(), ), - 0, ), ) w := httptest.NewRecorder() diff --git a/pool_test.go b/pool_test.go index edc9201..a342fd2 100644 --- a/pool_test.go +++ b/pool_test.go @@ -99,7 +99,7 @@ func TestClientPool_CreateClient_withErr(t *testing.T) { cpHasError := NewClientPool( SimpleClientFactory(func() (net.Conn, error) { return nil, fmt.Errorf("dummy error") - }, 10), + }), 10, 1*time.Millisecond, ) c, err := cpHasError.CreateClient() @@ -117,7 +117,7 @@ func TestClientPool_CreateClient_withErr(t *testing.T) { cpHasError = NewClientPool( SimpleClientFactory(func() (net.Conn, error) { return nil, fmt.Errorf("dummy error") - }, 0), + }), 0, 1*time.Millisecond, ) c, err = cpHasError.CreateClient() @@ -143,7 +143,7 @@ func TestClientPool_CreateClient_Return_0(t *testing.T) { conn := mockConn(false) atomic.AddUint64(&counter, 1) return &conn, nil - }, 0), + }), 0, 1000*time.Millisecond, ) @@ -195,7 +195,7 @@ func TestClientPool_CreateClient_Return_40(t *testing.T) { conn := mockConn(false) atomic.AddUint64(&counter, 1) return &conn, nil - }, 0), + }), 40, 1000*time.Millisecond, )