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
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
briar
briar
Commits
9528a8b6
Commit
9528a8b6
authored
12 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Minor refactoring and logging for reliability layer.
parent
28086e1a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java
+2
-2
2 additions, 2 deletions
briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java
briar-core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java
+11
-9
11 additions, 9 deletions
...core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java
with
13 additions
and
11 deletions
briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java
+
2
−
2
View file @
9528a8b6
...
...
@@ -69,7 +69,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
}
if
(!
foundBaudRate
)
throw
new
IOException
(
"Could not find a suitable baud rate"
);
reliabilityLayer
.
ini
t
();
reliabilityLayer
.
star
t
();
port
.
addEventListener
(
this
);
port
.
purgePort
(
PURGE_RXCLEAR
|
PURGE_TXCLEAR
);
port
.
writeBytes
(
"ATZ\r\n"
.
getBytes
(
"US-ASCII"
));
// Reset
...
...
@@ -144,7 +144,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
tryToClose
(
port
);
throw
new
IOException
(
e
.
toString
());
}
reliabilityLayer
.
invalidate
();
reliabilityLayer
.
stop
();
reliabilityLayer
=
new
ReliabilityLayer
(
this
);
connected
.
set
(
false
);
offHook
.
release
();
...
...
This diff is collapsed.
Click to expand it.
briar-core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java
+
11
−
9
View file @
9528a8b6
...
...
@@ -23,14 +23,14 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
private
volatile
ReceiverInputStream
inputStream
=
null
;
private
volatile
SenderOutputStream
outputStream
=
null
;
private
volatile
Thread
writer
=
null
;
private
volatile
boolean
valid
=
tru
e
;
private
volatile
boolean
running
=
fals
e
;
ReliabilityLayer
(
WriteHandler
writeHandler
)
{
this
.
writeHandler
=
writeHandler
;
writes
=
new
LinkedBlockingQueue
<
byte
[]>();
}
void
ini
t
()
{
void
star
t
()
{
SlipEncoder
encoder
=
new
SlipEncoder
(
this
);
Sender
sender
=
new
Sender
(
encoder
);
receiver
=
new
Receiver
(
sender
);
...
...
@@ -41,7 +41,7 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
@Override
public
void
run
()
{
try
{
while
(
valid
)
{
while
(
running
)
{
byte
[]
b
=
writes
.
take
();
if
(
b
.
length
==
0
)
return
;
// Poison pill
if
(
LOG
.
isLoggable
(
INFO
))
...
...
@@ -51,15 +51,16 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
}
catch
(
InterruptedException
e
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
warning
(
"Interrupted while writing"
);
valid
=
false
;
running
=
false
;
Thread
.
currentThread
().
interrupt
();
}
catch
(
IOException
e
)
{
if
(
LOG
.
isLoggable
(
WARNING
))
LOG
.
warning
(
"Interrupted while writing"
);
valid
=
false
;
running
=
false
;
}
}
};
running
=
true
;
writer
.
start
();
}
...
...
@@ -71,22 +72,23 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
return
outputStream
;
}
void
invalidate
()
{
valid
=
false
;
void
stop
()
{
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"Stopping reliability layer"
);
running
=
false
;
receiver
.
invalidate
();
writes
.
add
(
new
byte
[
0
]);
// Poison pill
}
// The modem calls this method to pass data up to the SLIP decoder
public
void
handleRead
(
byte
[]
b
)
throws
IOException
{
if
(!
valid
)
throw
new
IOException
(
"Connection closed"
);
if
(!
running
)
throw
new
IOException
(
"Connection closed"
);
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"Read "
+
b
.
length
+
" bytes"
);
decoder
.
handleRead
(
b
);
}
// The SLIP encoder calls this method to pass data down to the modem
public
void
handleWrite
(
byte
[]
b
)
throws
IOException
{
if
(!
valid
)
throw
new
IOException
(
"Connection closed"
);
if
(!
running
)
throw
new
IOException
(
"Connection closed"
);
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"Queueing "
+
b
.
length
+
" bytes"
);
if
(
b
.
length
>
0
)
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