Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 28 | using namespace android; |
| 29 | using namespace android::renderscript; |
| 30 | |
| 31 | FifoSocket::FifoSocket() { |
| 32 | sequence = 1; |
| 33 | } |
| 34 | |
| 35 | FifoSocket::~FifoSocket() { |
| 36 | |
| 37 | } |
| 38 | |
| 39 | bool FifoSocket::init() { |
| 40 | int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | void FifoSocket::shutdown() { |
| 45 | } |
| 46 | |
| 47 | void FifoSocket::writeAsync(const void *data, size_t bytes) { |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 48 | if (bytes == 0) { |
| 49 | return; |
| 50 | } |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 51 | //ALOGE("writeAsync %p %i", data, bytes); |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 52 | size_t ret = ::send(sv[0], data, bytes, 0); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 53 | //ALOGE("writeAsync ret %i", ret); |
Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 54 | rsAssert(ret == bytes); |
| 55 | } |
| 56 | |
| 57 | void FifoSocket::writeWaitReturn(void *retData, size_t retBytes) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 58 | //ALOGE("writeWaitReturn %p %i", retData, retBytes); |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 59 | size_t ret = ::recv(sv[0], retData, retBytes, 0); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 60 | //ALOGE("writeWaitReturn %i", ret); |
Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 61 | rsAssert(ret == retBytes); |
| 62 | } |
| 63 | |
| 64 | size_t FifoSocket::read(void *data, size_t bytes) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 65 | //ALOGE("read %p %i", data, bytes); |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 66 | size_t ret = ::recv(sv[1], data, bytes, 0); |
Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 67 | rsAssert(ret == bytes); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 68 | //ALOGE("read ret %i", ret); |
Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | void FifoSocket::readReturn(const void *data, size_t bytes) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 73 | ALOGE("readReturn %p %Zu", data, bytes); |
Jason Sams | edbfabd | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 74 | size_t ret = ::send(sv[1], data, bytes, 0); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame^] | 75 | ALOGE("readReturn %Zu", ret); |
Jason Sams | 7a22e10 | 2011-05-06 14:14:30 -0700 | [diff] [blame] | 76 | rsAssert(ret == bytes); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void FifoSocket::flush() { |
| 81 | } |
| 82 | |
| 83 | |