BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / serialconnect / FileSender.cpp
blob05be873c32afd465ee6fd829695d756dfb139a9f
1 /*
2 * Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk
3 * Distributed under terms of the MIT license.
4 */
7 #include "FileSender.h"
9 #include "SerialApp.h"
11 #include <DataIO.h>
12 #include <Message.h>
13 #include <SerialPort.h>
16 FileSender::~FileSender()
21 RawSender::RawSender(BDataIO* source, BSerialPort* sink, BHandler* listener)
23 // FIXME doing this all here in the constructor is not good. We need to
24 // do things asynchronously instead so as not to lock the application
25 // thread.
26 off_t sourceSize;
27 off_t position;
29 BPositionIO* pos = dynamic_cast<BPositionIO*>(source);
30 if (pos)
31 pos->GetSize(&sourceSize);
32 else
33 sourceSize = 0;
34 position = 0;
36 BMessenger messenger(listener);
38 uint8_t buffer[256];
39 for (;;) {
40 ssize_t s = source->Read(&buffer, sizeof(buffer));
41 if (s <= 0)
42 return;
44 sink->Write(buffer, s);
45 position += s;
47 BMessage msg(kMsgProgress);
48 msg.AddInt32("pos", position);
49 msg.AddInt32("size", sourceSize);
50 msg.AddString("info", "Sending" B_UTF8_ELLIPSIS);
51 messenger.SendMessage(&msg);
53 //usleep(20000);
58 RawSender::~RawSender()
63 bool
64 RawSender::BytesReceived(const uint8_t* data, size_t length)
66 // Nothing to do with received bytes, this protocol has no kind of
67 // acknowledgement from remote side.
68 return true;