blob: 8b8008d5c0a2d4086822326dc70f4929894acad8 [file] [log] [blame]
Jason Sams20087472011-05-06 14:14:30 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "rsFifoSocket.h"
18#include "utils/Timers.h"
19#include "utils/StopWatch.h"
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <ctype.h>
24#include <unistd.h>
25#include <sys/types.h>
26#include <sys/socket.h>
27
28using namespace android;
29using namespace android::renderscript;
30
31FifoSocket::FifoSocket() {
32 sequence = 1;
33}
34
35FifoSocket::~FifoSocket() {
36
37}
38
39bool FifoSocket::init() {
40 int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
41 return false;
42}
43
44void FifoSocket::shutdown() {
45}
46
47void FifoSocket::writeAsync(const void *data, size_t bytes) {
Jason Sams1a4efa32011-05-17 15:01:29 -070048 if (bytes == 0) {
49 return;
50 }
51 //LOGE("writeAsync %p %i", data, bytes);
52 size_t ret = ::send(sv[0], data, bytes, 0);
53 //LOGE("writeAsync ret %i", ret);
Jason Sams20087472011-05-06 14:14:30 -070054 rsAssert(ret == bytes);
55}
56
57void FifoSocket::writeWaitReturn(void *retData, size_t retBytes) {
Jason Sams1a4efa32011-05-17 15:01:29 -070058 //LOGE("writeWaitReturn %p %i", retData, retBytes);
59 size_t ret = ::recv(sv[0], retData, retBytes, 0);
60 //LOGE("writeWaitReturn %i", ret);
Jason Sams20087472011-05-06 14:14:30 -070061 rsAssert(ret == retBytes);
62}
63
64size_t FifoSocket::read(void *data, size_t bytes) {
Jason Sams1a4efa32011-05-17 15:01:29 -070065 //LOGE("read %p %i", data, bytes);
66 size_t ret = ::recv(sv[1], data, bytes, 0);
Jason Sams20087472011-05-06 14:14:30 -070067 rsAssert(ret == bytes);
Jason Sams1a4efa32011-05-17 15:01:29 -070068 //LOGE("read ret %i", ret);
Jason Sams20087472011-05-06 14:14:30 -070069 return ret;
70}
71
72void FifoSocket::readReturn(const void *data, size_t bytes) {
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070073 LOGE("readReturn %p %Zu", data, bytes);
Jason Sams1a4efa32011-05-17 15:01:29 -070074 size_t ret = ::send(sv[1], data, bytes, 0);
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070075 LOGE("readReturn %Zu", ret);
Jason Sams20087472011-05-06 14:14:30 -070076 rsAssert(ret == bytes);
77}
78
79
80void FifoSocket::flush() {
81}
82
83