+void MyPipeFrame::OnBtnSendFile(wxCommandEvent& WXUNUSED(event))
+{
+ wxFileDialog filedlg(this, _T("Select file to send"));
+ if ( filedlg.ShowModal() != wxID_OK )
+ return;
+
+ wxFFile file(filedlg.GetFilename(), _T("r"));
+ wxString data;
+ if ( !file.IsOpened() || !file.ReadAll(&data) )
+ return;
+
+ // can't write the entire string at once, this risk overflowing the pipe
+ // and we would dead lock
+ size_t len = data.length();
+ const wxChar *pc = data.c_str();
+ while ( len )
+ {
+ const size_t CHUNK_SIZE = 4096;
+ m_out.Write(pc, len > CHUNK_SIZE ? CHUNK_SIZE : len);
+
+ // note that not all data could have been written as we don't block on
+ // the write end of the pipe
+ const size_t lenChunk = m_out.LastWrite();
+
+ pc += lenChunk;
+ len -= lenChunk;
+
+ DoGet();
+ }
+}
+