4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
9 * Nikita Kalyazin <n.kalyazin@samsung.com>
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 * - Samsung RnD Institute Russia
38 #include "transfer_thread.h"
42 static void *transfer_thread(void *arg)
48 LOGI("transfer thread started\n");
52 nrd = splice(manager.buf_fd, NULL,
56 if (errno == EAGAIN) {
57 LOGI("No more data to read\n");
60 LOGE("Cannot splice read: %s\n", strerror(errno));
64 nwr = splice(fd_pipe[0], NULL,
65 manager.host.data_socket, NULL,
68 LOGE("Cannot splice write: %s\n", strerror(errno));
72 LOGW("nrd - nwr = %d\n", nrd - nwr);
78 LOGI("transfer thread finished\n");
87 if (manager.host.data_socket == -1) {
88 LOGW("won't start transfer thread: data socket isn't open\n");
92 if (manager.transfer_thread != -1) { // already started
93 LOGW("transfer already running\n");
97 saved_flags = fcntl(manager.buf_fd, F_GETFL);
98 fcntl(manager.buf_fd, F_SETFL, saved_flags & ~O_NONBLOCK);
100 if(pthread_create(&(manager.transfer_thread),
105 LOGE("Failed to create transfer thread\n");
116 if (manager.transfer_thread == -1) {
117 LOGI("transfer thread not running\n");
120 LOGI("stopping transfer\n");
123 saved_flags = fcntl(manager.buf_fd, F_GETFL);
124 fcntl(manager.buf_fd, F_SETFL, saved_flags | O_NONBLOCK);
125 pthread_join(manager.transfer_thread, NULL);
126 manager.transfer_thread = -1;
128 LOGI("transfer thread joined\n");