good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
5757a0ed
Commit
5757a0ed
authored
9 years ago
by
Bas van Kervel
Browse files
Options
Downloads
Patches
Plain Diff
added IPC timeout support
parent
04910c90
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rpc/codec/json.go
+34
-26
34 additions, 26 deletions
rpc/codec/json.go
with
34 additions
and
26 deletions
rpc/codec/json.go
+
34
−
26
View file @
5757a0ed
...
...
@@ -10,61 +10,69 @@ import (
)
const
(
READ_TIMEOUT
=
15
// read timeout in seconds
MAX_REQUEST_SIZE
=
1024
*
1024
MAX_RESPONSE_SIZE
=
1024
*
1024
)
// Json serialization support
type
JsonCodec
struct
{
c
net
.
Conn
buffer
[]
byte
bytesInBuffer
int
c
net
.
Conn
}
// Create new JSON coder instance
func
NewJsonCoder
(
conn
net
.
Conn
)
ApiCoder
{
return
&
JsonCodec
{
c
:
conn
,
buffer
:
make
([]
byte
,
MAX_REQUEST_SIZE
),
bytesInBuffer
:
0
,
c
:
conn
,
}
}
// Serialize obj to JSON and write it to conn
func
(
self
*
JsonCodec
)
ReadRequest
()
(
requests
[]
*
shared
.
Request
,
isBatch
bool
,
err
error
)
{
n
,
err
:=
self
.
c
.
Read
(
self
.
buffer
[
self
.
bytesInBuffer
:
])
if
err
!=
nil
{
self
.
bytesInBuffer
=
0
bytesInBuffer
:=
0
buf
:=
make
([]
byte
,
MAX_REQUEST_SIZE
)
deadline
:=
time
.
Now
()
.
Add
(
READ_TIMEOUT
*
time
.
Second
)
if
err
:=
self
.
c
.
SetDeadline
(
deadline
);
err
!=
nil
{
return
nil
,
false
,
err
}
self
.
bytesInBuffer
+=
n
for
{
n
,
err
:=
self
.
c
.
Read
(
buf
[
bytesInBuffer
:
])
if
err
!=
nil
{
self
.
c
.
Close
()
return
nil
,
false
,
err
}
bytesInBuffer
+=
n
singleRequest
:=
shared
.
Request
{}
err
=
json
.
Unmarshal
(
self
.
buffer
[
:
self
.
bytesInBuffer
],
&
singleRequest
)
if
err
==
nil
{
self
.
bytesInBuffer
=
0
requests
:=
make
([]
*
shared
.
Request
,
1
)
requests
[
0
]
=
&
singleRequest
return
requests
,
false
,
nil
}
singleRequest
:=
shared
.
Request
{}
err
=
json
.
Unmarshal
(
buf
[
:
bytesInBuffer
],
&
singleRequest
)
if
err
==
nil
{
requests
:=
make
([]
*
shared
.
Request
,
1
)
requests
[
0
]
=
&
singleRequest
return
requests
,
false
,
nil
}
requests
=
make
([]
*
shared
.
Request
,
0
)
err
=
json
.
Unmarshal
(
self
.
buffer
[
:
self
.
bytesInBuffer
],
&
requests
)
if
err
==
nil
{
self
.
bytesInBuffer
=
0
return
requests
,
true
,
nil
requests
=
make
([]
*
shared
.
Request
,
0
)
err
=
json
.
Unmarshal
(
buf
[
:
bytesInBuffer
],
&
requests
)
if
err
==
nil
{
return
requests
,
true
,
nil
}
}
return
nil
,
false
,
err
self
.
c
.
Close
()
// timeout
return
nil
,
false
,
fmt
.
Errorf
(
"Unable to read response"
)
}
func
(
self
*
JsonCodec
)
ReadResponse
()
(
interface
{},
error
)
{
bytesInBuffer
:=
0
buf
:=
make
([]
byte
,
MAX_RESPONSE_SIZE
)
deadline
:=
time
.
Now
()
.
Add
(
15
*
time
.
Second
)
self
.
c
.
SetDeadline
(
deadline
)
deadline
:=
time
.
Now
()
.
Add
(
READ_TIMEOUT
*
time
.
Second
)
if
err
:=
self
.
c
.
SetDeadline
(
deadline
);
err
!=
nil
{
return
nil
,
err
}
for
{
n
,
err
:=
self
.
c
.
Read
(
buf
[
bytesInBuffer
:
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment