Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Julian Dehm
briar
Commits
705b87b9
Commit
705b87b9
authored
12 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Writes to the reliability layer should be asynchronous.
The flow control window will limit the amount of buffered data.
parent
f8210e1b
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
src/net/sf/briar/plugins/modem/ReliabilityLayer.java
+42
-1
42 additions, 1 deletion
src/net/sf/briar/plugins/modem/ReliabilityLayer.java
with
42 additions
and
1 deletion
src/net/sf/briar/plugins/modem/ReliabilityLayer.java
+
42
−
1
View file @
705b87b9
package
net.sf.briar.plugins.modem
;
import
static
java
.
util
.
logging
.
Level
.
WARNING
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.logging.Logger
;
class
ReliabilityLayer
implements
ReadHandler
,
WriteHandler
{
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
ReliabilityLayer
.
class
.
getName
());
private
final
WriteHandler
writeHandler
;
private
final
Receiver
receiver
;
private
final
SlipDecoder
decoder
;
private
final
ReceiverInputStream
inputStream
;
private
final
SenderOutputStream
outputStream
;
private
final
BlockingQueue
<
byte
[]>
writes
;
private
volatile
boolean
valid
=
true
;
...
...
@@ -22,6 +31,31 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
decoder
=
new
SlipDecoder
(
receiver
);
inputStream
=
new
ReceiverInputStream
(
receiver
);
outputStream
=
new
SenderOutputStream
(
sender
);
writes
=
new
LinkedBlockingQueue
<
byte
[]>();
}
void
init
()
{
new
Thread
(
"ReliabilityLayer"
)
{
@Override
public
void
run
()
{
try
{
while
(
valid
)
{
byte
[]
b
=
writes
.
take
();
if
(
b
.
length
==
0
)
return
;
// Poison pill
writeHandler
.
handleWrite
(
b
,
b
.
length
);
}
}
catch
(
InterruptedException
e
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
warning
(
"Interrupted while writing"
);
valid
=
false
;
Thread
.
currentThread
().
interrupt
();
}
catch
(
IOException
e
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
warning
(
"Interrupted while writing"
);
valid
=
false
;
}
}
}.
start
();
}
InputStream
getInputStream
()
{
...
...
@@ -35,6 +69,7 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
void
invalidate
()
{
valid
=
false
;
receiver
.
invalidate
();
writes
.
add
(
new
byte
[
0
]);
// Poison pill
}
// The modem calls this method to pass data up to the SLIP decoder
...
...
@@ -46,6 +81,12 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
// The SLIP encoder calls this method to pass data down to the modem
public
void
handleWrite
(
byte
[]
b
,
int
length
)
throws
IOException
{
if
(!
valid
)
throw
new
IOException
(
"Connection closed"
);
writeHandler
.
handleWrite
(
b
,
length
);
if
(
length
==
0
)
return
;
if
(
length
<
b
.
length
)
{
byte
[]
copy
=
new
byte
[
length
];
System
.
arraycopy
(
b
,
0
,
copy
,
0
,
length
);
b
=
copy
;
}
writes
.
add
(
b
);
}
}
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