Bug 811683 - Changed UnixSocketRawData to take variable sizes up to 64k, r=cjones

This commit is contained in:
Kyle Machulis 2012-12-20 18:36:55 +08:00
Родитель 58e006628c
Коммит e6a69d942f
3 изменённых файлов: 15 добавлений и 24 удалений

Просмотреть файл

@ -596,7 +596,7 @@ BluetoothHfpManager::ReceiveSocketData(UnixSocketRawData* aMessage)
int currentCallState = mCurrentCallStateArray[mCurrentCallIndex];
nsAutoCString msg((const char*)aMessage->mData);
nsAutoCString msg((const char*)aMessage->mData.get());
msg.StripWhitespace();
nsTArray<nsCString> atCommandValues;

Просмотреть файл

@ -24,6 +24,8 @@
#include "nsTArray.h"
#include "nsXULAppAPI.h"
static const size_t MAX_READ_SIZE = 1 << 16;
#undef LOG
#if defined(MOZ_WIDGET_GONK)
#include <android/log.h>
@ -585,7 +587,7 @@ UnixSocketConsumer::SendSocketData(const nsACString& aStr)
if (!mImpl) {
return false;
}
if (aStr.Length() > UnixSocketRawData::MAX_DATA_SIZE) {
if (aStr.Length() > MAX_READ_SIZE) {
return false;
}
nsCString str(aStr);
@ -629,15 +631,14 @@ UnixSocketImpl::OnFileCanReadWithoutBlocking(int aFd)
// If so, break;
while (true) {
if (!mIncoming) {
mIncoming = new UnixSocketRawData();
ssize_t ret = read(aFd, mIncoming->mData, UnixSocketRawData::MAX_DATA_SIZE);
uint8_t data[MAX_READ_SIZE];
ssize_t ret = read(aFd, data, MAX_READ_SIZE);
if (ret <= 0) {
if (ret == -1) {
if (errno == EINTR) {
continue; // retry system call when interrupted
}
else if (errno == EAGAIN || errno == EWOULDBLOCK) {
mIncoming.forget();
return; // no data available: return and re-poll
}
// else fall through to error handling on other errno's
@ -647,19 +648,18 @@ UnixSocketImpl::OnFileCanReadWithoutBlocking(int aFd)
#endif
// At this point, assume that we can't actually access
// the socket anymore
mIncoming.forget();
mReadWatcher.StopWatchingFileDescriptor();
mWriteWatcher.StopWatchingFileDescriptor();
nsRefPtr<SocketCloseTask> t = new SocketCloseTask(this);
NS_DispatchToMainThread(t);
return;
}
mIncoming->mData[ret] = 0;
mIncoming->mSize = ret;
mIncoming = new UnixSocketRawData(ret);
memcpy(mIncoming->mData, data, ret);
nsRefPtr<SocketReceiveTask> t =
new SocketReceiveTask(this, mIncoming.forget());
NS_DispatchToMainThread(t);
if (ret < ssize_t(UnixSocketRawData::MAX_DATA_SIZE)) {
if (ret < ssize_t(MAX_READ_SIZE)) {
return;
}
}

Просмотреть файл

@ -16,26 +16,15 @@
namespace mozilla {
namespace ipc {
struct UnixSocketRawData
class UnixSocketRawData
{
static const size_t MAX_DATA_SIZE = 1024;
uint8_t mData[MAX_DATA_SIZE];
public:
nsAutoArrayPtr<uint8_t> mData;
// Number of octets in mData.
size_t mSize;
size_t mCurrentWriteOffset;
/**
* Constructor for situations where size is not known beforehand. (for
* example, when reading a packet)
*
*/
UnixSocketRawData() :
mSize(0),
mCurrentWriteOffset(0)
{
}
/**
* Constructor for situations where size is known beforehand (for example,
* when being assigned strings)
@ -45,8 +34,10 @@ struct UnixSocketRawData
mSize(aSize),
mCurrentWriteOffset(0)
{
mData = new uint8_t[aSize];
}
private:
UnixSocketRawData() {}
};
class UnixSocketImpl;