mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 811683 - Increase speed of sending file, r=gyeh
This commit is contained in:
parent
62d07093f9
commit
cd035247db
@ -17,6 +17,7 @@
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
@ -76,6 +77,13 @@ public:
|
||||
namespace {
|
||||
// Sending system message "bluetooth-opp-update-progress" every 50kb
|
||||
static const uint32_t kUpdateProgressBase = 50 * 1024;
|
||||
|
||||
/*
|
||||
* The format of the header of an PUT request is
|
||||
* [opcode:1][packet length:2][headerId:1][header length:2]
|
||||
*/
|
||||
static const uint32_t kPutRequestHeaderSize = 6;
|
||||
|
||||
StaticRefPtr<BluetoothOppManager> sInstance;
|
||||
StaticRefPtr<BluetoothOppManagerObserver> sOppObserver;
|
||||
|
||||
@ -114,24 +122,24 @@ BluetoothOppManagerObserver::Observe(nsISupports* aSubject,
|
||||
class ReadFileTask : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ReadFileTask(nsIInputStream* aInputStream) : mInputStream(aInputStream)
|
||||
ReadFileTask(nsIInputStream* aInputStream,
|
||||
uint32_t aRemoteMaxPacketSize) : mInputStream(aInputStream)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mAvailablePacketSize = aRemoteMaxPacketSize - kPutRequestHeaderSize;
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
/*
|
||||
* 255 is the Minimum OBEX Packet Length (See section 3.3.1.4,
|
||||
* IrOBEX ver 1.2)
|
||||
*/
|
||||
char buf[255];
|
||||
uint32_t numRead;
|
||||
nsAutoArrayPtr<char> buf;
|
||||
buf = new char[mAvailablePacketSize];
|
||||
|
||||
// function inputstream->Read() only works on non-main thread
|
||||
nsresult rv = mInputStream->Read(buf, sizeof(buf), &numRead);
|
||||
nsresult rv = mInputStream->Read(buf.get(), mAvailablePacketSize, &numRead);
|
||||
if (NS_FAILED(rv)) {
|
||||
// Needs error handling here
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -141,7 +149,7 @@ public:
|
||||
if (sSentFileLength + numRead >= sFileLength) {
|
||||
sWaitingToSendPutFinal = true;
|
||||
}
|
||||
sInstance->SendPutRequest((uint8_t*)buf, numRead);
|
||||
sInstance->SendPutRequest((uint8_t*)buf.get(), numRead);
|
||||
sSentFileLength += numRead;
|
||||
}
|
||||
|
||||
@ -150,6 +158,7 @@ public:
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
uint32_t mAvailablePacketSize;
|
||||
};
|
||||
|
||||
BluetoothOppManager::BluetoothOppManager() : mConnected(false)
|
||||
@ -829,7 +838,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
|
||||
}
|
||||
}
|
||||
|
||||
nsRefPtr<ReadFileTask> task = new ReadFileTask(mInputStream);
|
||||
nsRefPtr<ReadFileTask> task = new ReadFileTask(mInputStream,
|
||||
mRemoteMaxPacketLength);
|
||||
rv = mReadFileThread->Dispatch(task, NS_DISPATCH_NORMAL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Cannot dispatch read file task!");
|
||||
@ -915,8 +925,7 @@ void
|
||||
BluetoothOppManager::SendPutRequest(uint8_t* aFileBody,
|
||||
int aFileBodyLength)
|
||||
{
|
||||
int index = 3;
|
||||
int packetLeftSpace = mRemoteMaxPacketLength - index - 3;
|
||||
int packetLeftSpace = mRemoteMaxPacketLength - kPutRequestHeaderSize;
|
||||
|
||||
if (!mConnected) return;
|
||||
if (aFileBodyLength > packetLeftSpace) {
|
||||
@ -928,6 +937,7 @@ BluetoothOppManager::SendPutRequest(uint8_t* aFileBody,
|
||||
// [opcode:1][length:2][Headers:var]
|
||||
uint8_t* req = new uint8_t[mRemoteMaxPacketLength];
|
||||
|
||||
int index = 3;
|
||||
index += AppendHeaderBody(&req[index], aFileBody, aFileBodyLength);
|
||||
|
||||
SetObexPacketInfo(req, ObexRequestCode::Put, index);
|
||||
|
Loading…
Reference in New Issue
Block a user