Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
e7bae7d9
Commit
e7bae7d9
authored
Aug 06, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: use connection
parent
f46473b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
11 deletions
+19
-11
client.go
rpc/client.go
+14
-6
codec.go
rpc/codec.go
+1
-1
config.go
rpc/config.go
+3
-1
pool.go
rpc/pool.go
+1
-3
No files found.
rpc/client.go
View file @
e7bae7d9
...
...
@@ -4,10 +4,13 @@ import (
"math/rand"
"sync"
"time"
)
import
(
"github.com/AlexStocks/getty"
"github.com/AlexStocks/goext/sync/atomic"
"github.com/AlexStocks/goext/log"
jerrors
"github.com/juju/errors"
)
...
...
@@ -63,12 +66,17 @@ func (c *Client) Call(typ CodecType, addr, service, method string, args interfac
resp
:=
NewPendingResponse
()
resp
.
reply
=
reply
var
err
error
var
session
getty
.
Session
session
,
err
=
c
.
selectSession
(
typ
,
addr
)
var
(
err
error
session
getty
.
Session
conn
*
gettyRPCClientConn
)
conn
,
session
,
err
=
c
.
selectSession
(
typ
,
addr
)
gxlog
.
CError
(
"conn:%p, session:%p"
,
conn
,
session
)
if
err
!=
nil
||
session
==
nil
{
return
errSessionNotExist
}
defer
c
.
pool
.
release
(
conn
,
err
)
if
err
=
c
.
transfer
(
session
,
typ
,
b
,
resp
);
err
!=
nil
{
return
jerrors
.
Trace
(
err
)
...
...
@@ -92,12 +100,12 @@ func (c *Client) Close() {
c
.
pool
=
nil
}
func
(
c
*
Client
)
selectSession
(
typ
CodecType
,
addr
string
)
(
getty
.
Session
,
error
)
{
func
(
c
*
Client
)
selectSession
(
typ
CodecType
,
addr
string
)
(
*
gettyRPCClientConn
,
getty
.
Session
,
error
)
{
rpcConn
,
err
:=
c
.
pool
.
getConn
(
typ
.
String
(),
addr
)
if
err
!=
nil
{
return
nil
,
jerrors
.
Trace
(
err
)
return
nil
,
nil
,
jerrors
.
Trace
(
err
)
}
return
rpcConn
.
selectSession
(),
nil
return
rpcConn
,
rpcConn
.
selectSession
(),
nil
}
func
(
c
*
Client
)
heartbeat
(
session
getty
.
Session
,
typ
CodecType
)
error
{
...
...
rpc/codec.go
View file @
e7bae7d9
...
...
@@ -326,7 +326,7 @@ func NewGettyRPCRequest() RPCPackage {
func
(
req
*
GettyRPCRequest
)
Marshal
(
sz
CodecType
,
buf
*
bytes
.
Buffer
)
(
int
,
error
)
{
codec
:=
Codecs
[
sz
]
if
codec
==
nil
{
return
0
,
jerrors
.
Errorf
(
"can not find codec for %
d
"
,
sz
)
return
0
,
jerrors
.
Errorf
(
"can not find codec for %
s
"
,
sz
)
}
headerData
,
err
:=
codec
.
Encode
(
req
.
header
)
if
err
!=
nil
{
...
...
rpc/config.go
View file @
e7bae7d9
package
rpc
import
"time"
import
(
"time"
)
import
(
jerrors
"github.com/juju/errors"
...
...
rpc/pool.go
View file @
e7bae7d9
...
...
@@ -277,8 +277,6 @@ func (p *gettyRPCClientConnPool) getConn(protocol, addr string) (*gettyRPCClient
continue
}
p
.
Unlock
()
return
conn
,
nil
}
...
...
@@ -291,7 +289,7 @@ func (p *gettyRPCClientConnPool) release(conn *gettyRPCClientConn, err error) {
return
}
if
err
!=
nil
{
conn
.
close
()
//
conn
.
close
()
return
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment