Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Andreas Kempe
mpi-mandelbrot
Commits
4f84899a
Commit
4f84899a
authored
Oct 03, 2015
by
Andreas Kempe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The server will now wait until all data is sent on the socket.
parent
a28bf5d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
network/mandel_socket.cpp
network/mandel_socket.cpp
+21
-3
network/mandel_socket.h
network/mandel_socket.h
+7
-0
server/main.cpp
server/main.cpp
+6
-1
No files found.
network/mandel_socket.cpp
View file @
4f84899a
...
...
@@ -7,13 +7,14 @@
using
namespace
std
;
mandel_socket
::
mandel_socket
(
QString
host
,
unsigned
int
port
,
QObject
*
parent
)
:
QTcpSocket
(
parent
)
QTcpSocket
(
parent
)
,
transmission_done
(
false
),
bytes_written
(
0
),
bytes_to_write
(
0
)
{
setup_slot_connection
();
connectToHost
(
host
,
port
,
QIODevice
::
ReadWrite
,
QAbstractSocket
::
AnyIPProtocol
);
}
mandel_socket
::
mandel_socket
(
QObject
*
parent
)
:
QTcpSocket
(
parent
)
mandel_socket
::
mandel_socket
(
QObject
*
parent
)
:
QTcpSocket
(
parent
),
transmission_done
(
false
),
bytes_written
(
0
),
bytes_to_write
(
0
)
{
setup_slot_connection
();
}
...
...
@@ -35,7 +36,10 @@ void mandel_socket::send_data_packet(const data_packet& packet)
stream
<<
packet
;
write
(
buf
);
flush
();
transmission_done
=
false
;
bytes_written
=
0
;
bytes_to_write
=
buf
.
size
();
}
data_packet
*
mandel_socket
::
get_next_packet
()
...
...
@@ -49,9 +53,15 @@ data_packet* mandel_socket::get_next_packet()
return
tmp
;
}
bool
mandel_socket
::
is_transmission_done
()
{
return
transmission_done
;
}
void
mandel_socket
::
setup_slot_connection
()
{
connect
(
this
,
&
mandel_socket
::
readyRead
,
this
,
&
mandel_socket
::
handle_recv_data
);
connect
(
this
,
&
mandel_socket
::
bytesWritten
,
this
,
&
mandel_socket
::
handle_bytes_written
);
}
void
mandel_socket
::
decode_packet_data
(
QByteArray
&
incoming
)
...
...
@@ -102,3 +112,11 @@ void mandel_socket::handle_recv_data()
decode_packet_data
(
incoming
);
}
void
mandel_socket
::
handle_bytes_written
(
qint64
written_bytes
)
{
bytes_written
+=
written_bytes
;
if
(
bytes_written
>=
bytes_to_write
)
transmission_done
=
true
;
}
network/mandel_socket.h
View file @
4f84899a
...
...
@@ -16,6 +16,8 @@ class mandel_socket : public QTcpSocket
void
send_data_packet
(
const
data_packet
&
packet
);
data_packet
*
get_next_packet
();
bool
is_transmission_done
();
private:
void
setup_slot_connection
();
...
...
@@ -25,8 +27,13 @@ class mandel_socket : public QTcpSocket
void
handle_op_code
(
const
QByteArray
&
data
);
void
decode_packet_data
(
QByteArray
&
incoming
);
bool
transmission_done
;
qint64
bytes_written
;
qint64
bytes_to_write
;
private
slots
:
void
handle_recv_data
();
void
handle_bytes_written
(
qint64
written_bytes
);
signals:
void
packet_ready
();
...
...
server/main.cpp
View file @
4f84899a
...
...
@@ -50,7 +50,7 @@ void root_process_handling(unsigned long *receive_buffer)
cout
<<
"Sending image!"
<<
endl
;
mandel_socket
socket
(
"1
27.0.0.1
"
,
PORT
,
nullptr
);
mandel_socket
socket
(
"1
92.168.1.2
"
,
PORT
,
nullptr
);
socket
.
waitForConnected
(
10000
);
Blob
image_data
;
...
...
@@ -64,6 +64,11 @@ void root_process_handling(unsigned long *receive_buffer)
data_packet
packet
(
op_codes
::
IMG_DATA
,
enc_img
.
size
()
+
1
,
data
);
socket
.
send_data_packet
(
packet
);
// Since we don't have an event loop (yet?)
// we'll wait for the socket to finish sending its data.
while
(
!
socket
.
is_transmission_done
())
socket
.
waitForBytesWritten
();
}
...
...
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