• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <math.h>
19 #include <ohos_init.h>
20 #include <pthread.h>
21 #include <signal.h>
22 #include <stdlib.h>
23 #include <time.h>
24 #include <unistd.h>
25 
26 #include "client_business_impl.h"
27 #include "client_callback.h"
28 #include "common.h"
29 #include "ipc_skeleton.h"
30 #include "iproxy_client.h"
31 #include "rpc_errno.h"
32 #include "rpc_log.h"
33 #include "samgr_lite.h"
34 #include "serializer.h"
35 
36 #define WAIT_SERVER_READY_INTERVAL_COUNT 50
37 #define CLIENT_TEST_NUMBER 100
38 #define PI acosl(-1)
39 #define CLIENT_VECTOR_LEN 10
40 #define INVALID_FD (-1)
41 #define FD_TIMEOUT 10 // 10s
42 #define CLIENT_SEND_STRING "im client"
43 
44 #define InitSendData(ioPtr, data, dataType) \
45     uint8_t tmpData[IPC_BUFFER_SIZE] = {0}; \
46     IpcIoInit((ioPtr), tmpData, IPC_BUFFER_SIZE, OBJ_NUM); \
47     Write##dataType((ioPtr), (data))
48 
49 #define InitSendPtr(ioPtr, dataPtr, dataType, size) \
50     uint8_t tmpData[IPC_BUFFER_SIZE] = {0}; \
51     IpcIoInit((ioPtr), tmpData, IPC_BUFFER_SIZE, OBJ_NUM); \
52     Write##dataType((ioPtr), (dataPtr), (size))
53 
54 static SvcIdentity g_clientIdentify;
55 static IClientProxy *g_serverProxy = NULL;
56 static int g_pipeFd[2] = {INVALID_FD, INVALID_FD};
57 static pthread_mutex_t g_pipeFdMutex = PTHREAD_MUTEX_INITIALIZER;
58 
InitPipe()59 static int32_t InitPipe()
60 {
61     pthread_mutex_lock(&g_pipeFdMutex);
62     if (g_pipeFd[0] != INVALID_FD || g_pipeFd[1] != INVALID_FD) {
63         RPC_LOG_INFO("[ipc_test_client] pipe already init");
64         pthread_mutex_unlock(&g_pipeFdMutex);
65         return ERR_NONE;
66     }
67 
68     if (pipe(g_pipeFd) < 0) {
69         RPC_LOG_ERROR("[ipc_test_client] create pipe error");
70         pthread_mutex_unlock(&g_pipeFdMutex);
71         return ERR_FAILED;
72     }
73     pthread_mutex_unlock(&g_pipeFdMutex);
74     return ERR_NONE;
75 }
76 
DeinitPipe()77 static void DeinitPipe()
78 {
79     pthread_mutex_lock(&g_pipeFdMutex);
80     if (g_pipeFd[1] != INVALID_FD) {
81         close(g_pipeFd[1]);
82     }
83     if (g_pipeFd[0] != INVALID_FD) {
84         close(g_pipeFd[0]);
85     }
86     g_pipeFd[1] = INVALID_FD;
87     g_pipeFd[0] = INVALID_FD;
88     pthread_mutex_unlock(&g_pipeFdMutex);
89     return;
90 }
91 
StartTimerForFdEvent()92 static int32_t StartTimerForFdEvent()
93 {
94     struct sigevent event = {
95         .sigev_notify = SIGEV_THREAD,
96         .sigev_notify_function = DeinitPipe,
97     };
98     timer_t timerid;
99     if (timer_create(CLOCK_REALTIME, &event, &timerid) == -1) {
100         RPC_LOG_ERROR("[ipc_test_client] timer_create error");
101         return ERR_FAILED;
102     }
103     struct itimerspec its = {
104         .it_value.tv_sec = FD_TIMEOUT
105     };
106     if (timer_settime(timerid, 0, &its, NULL) == -1) {
107         RPC_LOG_ERROR("[ipc_test_client] timer_settime error");
108         return ERR_FAILED;
109     }
110     RPC_LOG_INFO("[ipc_test_client] start timer wait timeout success");
111     return ERR_NONE;
112 }
113 
SetClientIdentity(unsigned int handle,uintptr_t token,uintptr_t cookie)114 static void SetClientIdentity(unsigned int handle, uintptr_t token, uintptr_t cookie)
115 {
116     g_clientIdentify.handle = handle;
117     g_clientIdentify.token = token;
118     g_clientIdentify.cookie = cookie;
119     return;
120 }
121 
GetServerProxy(void)122 static IClientProxy *GetServerProxy(void)
123 {
124     IClientProxy *clientProxy = NULL;
125 
126     RPC_LOG_INFO("[ipc_test_client] start get client proxy");
127     int32_t proxyInitCount = 0;
128     while (clientProxy == NULL) {
129         proxyInitCount++;
130         if (proxyInitCount == WAIT_SERVER_READY_INTERVAL_COUNT) {
131             RPC_LOG_ERROR("[ipc_test_client] get server proxy error");
132             return NULL;
133         }
134         IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(IPC_TEST_SMALL);
135         if (iUnknown == NULL) {
136             RPC_LOG_ERROR("iUnknown is null");
137             sleep(1);
138             continue;
139         }
140         RPC_LOG_INFO("[ipc_test_client] GetDefaultFeatureApi success");
141 
142         int32_t ret = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&clientProxy);
143         if (ret != EC_SUCCESS || clientProxy == NULL) {
144             RPC_LOG_ERROR("QueryInterface failed [%d]", ret);
145             sleep(1);
146             continue;
147         }
148     }
149 
150     RPC_LOG_INFO("[ipc_test_client] get client proxy ok");
151     return clientProxy;
152 }
153 
DoSend(IpcIo * data,int32_t messageCode,bool isAsync)154 static int32_t DoSend(IpcIo *data, int32_t messageCode, bool isAsync)
155 {
156     // client send data through samgr_lite
157     if (messageCode <= TYPE_START || messageCode >= TYPE_END) {
158         RPC_LOG_ERROR("[ipc_test_client] messageCode error, code=%d", messageCode);
159         return ERR_INVALID_PARAM;
160     }
161 
162     // callback==NULL will send TF_OP_ASYNC message, else TF_OP_SYNC
163     Reply reply = {.id = messageCode};
164     int32_t ans = g_serverProxy->Invoke(g_serverProxy, (uint32_t)messageCode,
165         data, &reply, isAsync ? NULL : ClientSendSyncMessageCallback);
166     if (ans != ERR_NONE) {
167         RPC_LOG_ERROR("[ipc_test_client] DoSend error, code=%d, ret=%d", messageCode, ans);
168         return ERR_FAILED;
169     }
170     return ERR_NONE;
171 }
172 
RemoteRequest(uint32_t code,IpcIo * data,IpcIo * reply,MessageOption option)173 static int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
174 {
175     (void)data;
176     (void)reply;
177     (void)option;
178     RPC_LOG_ERROR("[ipc_test_client] RemoteRequest is called, code=%u", code);
179     return ERR_NONE;
180 }
181 
InitLocalIdentity()182 void InitLocalIdentity()
183 {
184     static IpcObjectStub objectStub = {
185         .func = RemoteRequest,
186         .args = NULL,
187         .isRemote = false
188     };
189     SvcIdentity clientIdentity = {
190         .handle = IPC_INVALID_HANDLE,
191         .token = SERVICE_TYPE_ANONYMOUS,
192         .cookie = (uintptr_t)&objectStub
193     };
194     // save to local
195     SetClientIdentity(clientIdentity.handle, clientIdentity.token, clientIdentity.cookie);
196     return;
197 }
198 
RegisterToService()199 void RegisterToService()
200 {
201     g_serverProxy = GetServerProxy();
202     if (g_serverProxy == NULL) {
203         RPC_LOG_ERROR("[ipc_test_client] g_serverProxy null");
204         return;
205     }
206 
207     // write pkgname and svc
208     IpcIo request;
209     uint8_t temData[IPC_BUFFER_SIZE];
210     IpcIoInit(&request, temData, IPC_BUFFER_SIZE, OBJ_NUM);
211     WriteString(&request, (char *)IPC_TEST_SMALL);
212     if (!WriteRemoteObject(&request, &g_clientIdentify)) {
213         RPC_LOG_ERROR("[ipc_test_client] WriteRemoteObject error");
214     }
215 
216     int32_t ret = ERR_FAILED;
217     if (g_serverProxy->Invoke(g_serverProxy, REGISTER_ON_SERVICE, &request, &ret, NULL) != ERR_NONE) {
218         RPC_LOG_INFO("[ipc_test_client] invoker error");
219         return;
220     }
221     RPC_LOG_INFO("[ipc_test_client] RegisterToService start");
222     return;
223 }
224 
SendBool()225 void SendBool()
226 {
227     RPC_LOG_INFO("[ipc_test_client] ------ SendBool start ------");
228     IpcIo io;
229     IpcIo *ioPtr = &io;
230     bool sendData = false;
231     InitSendData(ioPtr, sendData, Bool);
232 
233     // send sync to server
234     (void)DoSend(ioPtr, BOOL_TYPE, false);
235 
236     // send async to server
237     (void)DoSend(ioPtr, BOOL_TYPE, true);
238     RPC_LOG_INFO("[ipc_test_client] ------ SendBool end ------");
239     return;
240 }
241 
SendInt8()242 void SendInt8()
243 {
244     RPC_LOG_INFO("[ipc_test_client] ------ SendInt8 start ------");
245     IpcIo io;
246     IpcIo *ioPtr = &io;
247     int8_t sendData = CLIENT_TEST_NUMBER;
248     InitSendData(ioPtr, sendData, Int8);
249 
250     // send sync to server
251     (void)DoSend(ioPtr, INT8_TYPE, false);
252 
253     // send async to server
254     (void)DoSend(ioPtr, INT8_TYPE, true);
255     RPC_LOG_INFO("[ipc_test_client] ------ SendInt8 end ------");
256     return;
257 }
258 
SendInt16()259 void SendInt16()
260 {
261     RPC_LOG_INFO("[ipc_test_client] ------ SendInt16 start ------");
262     IpcIo io;
263     IpcIo *ioPtr = &io;
264     int16_t sendData = CLIENT_TEST_NUMBER;
265     InitSendData(ioPtr, sendData, Int16);
266 
267     // send sync to server
268     (void)DoSend(ioPtr, INT16_TYPE, false);
269 
270     // send async to server
271     (void)DoSend(ioPtr, INT16_TYPE, true);
272     RPC_LOG_INFO("[ipc_test_client] ------ SendInt16 end ------");
273     return;
274 }
275 
SendInt32()276 void SendInt32()
277 {
278     RPC_LOG_INFO("[ipc_test_client] ------ SendInt32 start ------");
279     IpcIo io;
280     IpcIo *ioPtr = &io;
281     int32_t sendData = CLIENT_TEST_NUMBER;
282     InitSendData(ioPtr, sendData, Int32);
283 
284     // send sync to server
285     (void)DoSend(ioPtr, INT32_TYPE, false);
286 
287     // send async to server
288     (void)DoSend(ioPtr, INT32_TYPE, true);
289     RPC_LOG_INFO("[ipc_test_client] ------ SendInt32 end ------");
290     return;
291 }
292 
SendInt64()293 void SendInt64()
294 {
295     RPC_LOG_INFO("[ipc_test_client] ------ SendInt64 start ------");
296     IpcIo io;
297     IpcIo *ioPtr = &io;
298     int64_t sendData = CLIENT_TEST_NUMBER;
299     InitSendData(ioPtr, sendData, Int64);
300 
301     // send sync to server
302     (void)DoSend(ioPtr, INT64_TYPE, false);
303 
304     // send async to server
305     (void)DoSend(ioPtr, INT64_TYPE, true);
306     RPC_LOG_INFO("[ipc_test_client] ------ SendInt64 end ------");
307     return;
308 }
309 
SendUint8()310 void SendUint8()
311 {
312     RPC_LOG_INFO("[ipc_test_client] ------ SendUint8 start ------");
313     IpcIo io;
314     IpcIo *ioPtr = &io;
315     uint8_t sendData = CLIENT_TEST_NUMBER;
316     InitSendData(ioPtr, sendData, Uint8);
317 
318     // send sync to server
319     (void)DoSend(ioPtr, UINT8_TYPE, false);
320 
321     // send async to server
322     (void)DoSend(ioPtr, UINT8_TYPE, true);
323     RPC_LOG_INFO("[ipc_test_client] ------ SendUint8 end ------");
324     return;
325 }
326 
SendUint16()327 void SendUint16()
328 {
329     RPC_LOG_INFO("[ipc_test_client] ------ SendUint16 start ------");
330     IpcIo io;
331     IpcIo *ioPtr = &io;
332     uint16_t sendData = CLIENT_TEST_NUMBER;
333     InitSendData(ioPtr, sendData, Uint16);
334 
335     // send sync to server
336     (void)DoSend(ioPtr, UINT16_TYPE, false);
337 
338     // send async to server
339     (void)DoSend(ioPtr, UINT16_TYPE, true);
340     RPC_LOG_INFO("[ipc_test_client] ------ SendUint16 end ------");
341     return;
342 }
343 
SendUint32()344 void SendUint32()
345 {
346     RPC_LOG_INFO("[ipc_test_client] ------ SendUint32 start ------");
347     IpcIo io;
348     IpcIo *ioPtr = &io;
349     uint32_t sendData = CLIENT_TEST_NUMBER;
350     InitSendData(ioPtr, sendData, Uint32);
351 
352     // send sync to server
353     (void)DoSend(ioPtr, UINT32_TYPE, false);
354 
355     // send async to server
356     (void)DoSend(ioPtr, UINT32_TYPE, true);
357     RPC_LOG_INFO("[ipc_test_client] ------ SendUint32 end ------");
358     return;
359 }
360 
SendUint64()361 void SendUint64()
362 {
363     RPC_LOG_INFO("[ipc_test_client] ------ SendUint64 start ------");
364     IpcIo io;
365     IpcIo *ioPtr = &io;
366     uint64_t sendData = CLIENT_TEST_NUMBER;
367     InitSendData(ioPtr, sendData, Uint64);
368 
369     // send sync to server
370     (void)DoSend(ioPtr, UINT64_TYPE, false);
371 
372     // send async to server
373     (void)DoSend(ioPtr, UINT64_TYPE, true);
374     RPC_LOG_INFO("[ipc_test_client] ------ SendUint64 end ------");
375     return;
376 }
377 
SendFloat()378 void SendFloat()
379 {
380     RPC_LOG_INFO("[ipc_test_client] ------ SendFloat start ------");
381     IpcIo io;
382     IpcIo *ioPtr = &io;
383     float sendData = PI;
384     InitSendData(ioPtr, sendData, Float);
385 
386     // send sync to server
387     (void)DoSend(ioPtr, FLOAT_TYPE, false);
388 
389     // send async to server
390     (void)DoSend(ioPtr, FLOAT_TYPE, true);
391     RPC_LOG_INFO("[ipc_test_client] ------ SendFloat end ------");
392     return;
393 }
394 
SendDouble()395 void SendDouble()
396 {
397     RPC_LOG_INFO("[ipc_test_client] ------ SendDouble start ------");
398     IpcIo io;
399     IpcIo *ioPtr = &io;
400     double sendData = PI;
401     InitSendData(ioPtr, sendData, Double);
402 
403     // send sync to server
404     (void)DoSend(ioPtr, DOUBLE_TYPE, false);
405 
406     // send async to server
407     (void)DoSend(ioPtr, DOUBLE_TYPE, true);
408     RPC_LOG_INFO("[ipc_test_client] ------ SendDouble end ------");
409     return;
410 }
411 
SendInt8Vector()412 void SendInt8Vector()
413 {
414     RPC_LOG_INFO("[ipc_test_client] ------ SendInt8Vector start ------");
415     IpcIo io;
416     IpcIo *ioPtr = &io;
417     int8_t sendData[CLIENT_VECTOR_LEN];
418     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
419         sendData[i] = CLIENT_TEST_NUMBER + i;
420     }
421     InitSendPtr(ioPtr, sendData, Int8Vector, CLIENT_VECTOR_LEN);
422     // send sync to server
423     (void)DoSend(ioPtr, VECTOR_INT8_TYPE, false);
424 
425     // send async to server
426     (void)DoSend(ioPtr, VECTOR_INT8_TYPE, true);
427     RPC_LOG_INFO("[ipc_test_client] ------ SendInt8Vector end ------");
428     return;
429 }
430 
SendInt16Vector()431 void SendInt16Vector()
432 {
433     RPC_LOG_INFO("[ipc_test_client] ------ SendInt16Vector start ------");
434     IpcIo io;
435     IpcIo *ioPtr = &io;
436     int16_t sendData[CLIENT_VECTOR_LEN];
437     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
438         sendData[i] = CLIENT_TEST_NUMBER + i;
439     }
440     InitSendPtr(ioPtr, sendData, Int16Vector, CLIENT_VECTOR_LEN);
441     // send sync to server
442     (void)DoSend(ioPtr, VECTOR_INT16_TYPE, false);
443 
444     // send async to server
445     (void)DoSend(ioPtr, VECTOR_INT16_TYPE, true);
446     RPC_LOG_INFO("[ipc_test_client] ------ SendInt16Vector end ------");
447     return;
448 }
449 
SendInt32Vector()450 void SendInt32Vector()
451 {
452     RPC_LOG_INFO("[ipc_test_client] ------ SendInt32Vector start ------");
453     IpcIo io;
454     IpcIo *ioPtr = &io;
455     int32_t sendData[CLIENT_VECTOR_LEN];
456     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
457         sendData[i] = CLIENT_TEST_NUMBER + i;
458     }
459     InitSendPtr(ioPtr, sendData, Int32Vector, CLIENT_VECTOR_LEN);
460     // send sync to server
461     (void)DoSend(ioPtr, VECTOR_INT32_TYPE, false);
462 
463     // send async to server
464     (void)DoSend(ioPtr, VECTOR_INT32_TYPE, true);
465     RPC_LOG_INFO("[ipc_test_client] ------ SendInt32Vector end ------");
466     return;
467 }
468 
SendInt64Vector()469 void SendInt64Vector()
470 {
471     RPC_LOG_INFO("[ipc_test_client] ------ SendInt64Vector start ------");
472     IpcIo io;
473     IpcIo *ioPtr = &io;
474     int64_t sendData[CLIENT_VECTOR_LEN];
475     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
476         sendData[i] = CLIENT_TEST_NUMBER + i;
477     }
478     InitSendPtr(ioPtr, sendData, Int64Vector, CLIENT_VECTOR_LEN);
479     // send sync to server
480     (void)DoSend(ioPtr, VECTOR_INT64_TYPE, false);
481 
482     // send async to server
483     (void)DoSend(ioPtr, VECTOR_INT64_TYPE, true);
484     RPC_LOG_INFO("[ipc_test_client] ------ SendInt64Vector end ------");
485     return;
486 }
487 
SendUint8Vector()488 void SendUint8Vector()
489 {
490     RPC_LOG_INFO("[ipc_test_client] ------ SendUint8Vector start ------");
491     IpcIo io;
492     IpcIo *ioPtr = &io;
493     uint8_t sendData[CLIENT_VECTOR_LEN];
494     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
495         sendData[i] = CLIENT_TEST_NUMBER + i;
496     }
497     InitSendPtr(ioPtr, sendData, UInt8Vector, CLIENT_VECTOR_LEN);
498     // send sync to server
499     (void)DoSend(ioPtr, VECTOR_UINT8_TYPE, false);
500 
501     // send async to server
502     (void)DoSend(ioPtr, VECTOR_UINT8_TYPE, true);
503     RPC_LOG_INFO("[ipc_test_client] ------ SendUint8Vector end ------");
504     return;
505 }
506 
SendUint16Vector()507 void SendUint16Vector()
508 {
509     RPC_LOG_INFO("[ipc_test_client] ------ SendUint16Vector start ------");
510     IpcIo io;
511     IpcIo *ioPtr = &io;
512     uint16_t sendData[CLIENT_VECTOR_LEN];
513     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
514         sendData[i] = CLIENT_TEST_NUMBER + i;
515     }
516     InitSendPtr(ioPtr, sendData, UInt16Vector, CLIENT_VECTOR_LEN);
517     // send sync to server
518     (void)DoSend(ioPtr, VECTOR_UINT16_TYPE, false);
519 
520     // send async to server
521     (void)DoSend(ioPtr, VECTOR_UINT16_TYPE, true);
522     RPC_LOG_INFO("[ipc_test_client] ------ SendUint16Vector end ------");
523     return;
524 }
525 
SendUint32Vector()526 void SendUint32Vector()
527 {
528     RPC_LOG_INFO("[ipc_test_client] ------ SendUint32Vector start ------");
529     IpcIo io;
530     IpcIo *ioPtr = &io;
531     uint32_t sendData[CLIENT_VECTOR_LEN];
532     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
533         sendData[i] = CLIENT_TEST_NUMBER + i;
534     }
535     InitSendPtr(ioPtr, sendData, UInt32Vector, CLIENT_VECTOR_LEN);
536     // send sync to server
537     (void)DoSend(ioPtr, VECTOR_UINT32_TYPE, false);
538 
539     // send async to server
540     (void)DoSend(ioPtr, VECTOR_UINT32_TYPE, true);
541     RPC_LOG_INFO("[ipc_test_client] ------ SendUint32Vector end ------");
542     return;
543 }
544 
SendUint64Vector()545 void SendUint64Vector()
546 {
547     RPC_LOG_INFO("[ipc_test_client] ------ SendUint64Vector start ------");
548     IpcIo io;
549     IpcIo *ioPtr = &io;
550     uint64_t sendData[CLIENT_VECTOR_LEN];
551     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
552         sendData[i] = CLIENT_TEST_NUMBER + i;
553     }
554     InitSendPtr(ioPtr, sendData, UInt64Vector, CLIENT_VECTOR_LEN);
555     // send sync to server
556     (void)DoSend(ioPtr, VECTOR_UINT64_TYPE, false);
557 
558     // send async to server
559     (void)DoSend(ioPtr, VECTOR_UINT64_TYPE, true);
560     RPC_LOG_INFO("[ipc_test_client] ------ SendUint64Vector end ------");
561     return;
562 }
563 
SendFloatVector()564 void SendFloatVector()
565 {
566     RPC_LOG_INFO("[ipc_test_client] ------ SendFloatVector start ------");
567     IpcIo io;
568     IpcIo *ioPtr = &io;
569     float sendData[CLIENT_VECTOR_LEN];
570     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
571         sendData[i] = PI + i;
572     }
573     InitSendPtr(ioPtr, sendData, FloatVector, CLIENT_VECTOR_LEN);
574     // send sync to server
575     (void)DoSend(ioPtr, VECTOR_FLOAT_TYPE, false);
576 
577     // send async to server
578     (void)DoSend(ioPtr, VECTOR_FLOAT_TYPE, true);
579     RPC_LOG_INFO("[ipc_test_client] ------ SendFloatVector end ------");
580     return;
581 }
582 
SendDoubleVector()583 void SendDoubleVector()
584 {
585     RPC_LOG_INFO("[ipc_test_client] ------ SendDoubleVector start ------");
586     IpcIo io;
587     IpcIo *ioPtr = &io;
588     double sendData[CLIENT_VECTOR_LEN];
589     for (int i = 0; i < CLIENT_VECTOR_LEN; i++) {
590         sendData[i] = PI + i;
591     }
592     InitSendPtr(ioPtr, sendData, DoubleVector, CLIENT_VECTOR_LEN);
593     // send sync to server
594     (void)DoSend(ioPtr, VECTOR_DOUBLE_TYPE, false);
595 
596     // send async to server
597     (void)DoSend(ioPtr, VECTOR_DOUBLE_TYPE, true);
598     RPC_LOG_INFO("[ipc_test_client] ------ SendDoubleVector end ------");
599     return;
600 }
601 
SendString()602 void SendString()
603 {
604     RPC_LOG_INFO("[ipc_test_client] ------ SendString start ------");
605     IpcIo io;
606     IpcIo *ioPtr = &io;
607     const char *sendData = (char *)CLIENT_SEND_STRING;
608     InitSendData(ioPtr, sendData, String);
609 
610     // send sync to server
611     (void)DoSend(ioPtr, CHAR_TYPE, false);
612 
613     // send async to server
614     (void)DoSend(ioPtr, CHAR_TYPE, true);
615     RPC_LOG_INFO("[ipc_test_client] ------ SendString end ------");
616     return;
617 }
618 
SendFileDescriptor()619 void SendFileDescriptor()
620 {
621     RPC_LOG_INFO("[ipc_test_client] ------ SendFileDescriptor start ------");
622     IpcIo io;
623     IpcIo *ioPtr = &io;
624     if (InitPipe() != ERR_NONE) {
625         return;
626     }
627 
628     if (StartTimerForFdEvent() != ERR_NONE) {
629         return;
630     }
631 
632     InitSendData(ioPtr, g_pipeFd[1], FileDescriptor);
633     (void)DoSend(ioPtr, FD_TYPE, false);
634 
635     // block on response or timeout
636     char buffer[100];
637     RPC_LOG_INFO("[ipc_test_client] SendFileDescriptor waiting for data reading, timeout=%d...", (int32_t)FD_TIMEOUT);
638     ssize_t readLen = read(g_pipeFd[0], buffer, sizeof(buffer));
639     if (readLen == 0) {
640         RPC_LOG_ERROR("[ipc_test_client] SendFileDescriptor read error, read timeout");
641     } else if (readLen < 0) {
642         RPC_LOG_ERROR("[ipc_test_client] SendFileDescriptor read failed, err=%d", errno);
643         DeinitPipe();
644     } else {
645         buffer[readLen] = '\0';
646         RPC_LOG_INFO("[ipc_test_client] SendFileDescriptor receive size=%d data=%s", readLen, buffer);
647         DeinitPipe();
648     }
649     RPC_LOG_INFO("[ipc_test_client] ------ SendFileDescriptor end ------");
650     return;
651 }
652 
SendRawData()653 void SendRawData()
654 {
655     RPC_LOG_INFO("[ipc_test_client] ------ SendRawData start ------");
656     IpcIo io;
657     IpcIo *ioPtr = &io;
658     InitSendPtr(ioPtr, &g_clientIdentify, RawData, sizeof(SvcIdentity));
659 
660     // send sync to server
661     (void)DoSend(ioPtr, RAW_DATA_TYPE, false);
662 
663     // send async to server
664     (void)DoSend(ioPtr, RAW_DATA_TYPE, true);
665     RPC_LOG_INFO("[ipc_test_client] ------ SendRawData end ------");
666     return;
667 }
668 
SendBuffer()669 void SendBuffer()
670 {
671     RPC_LOG_INFO("[ipc_test_client] ------ SendBuffer start ------");
672     IpcIo io;
673     IpcIo *ioPtr = &io;
674     // send struct svc test
675     InitSendPtr(ioPtr, &g_clientIdentify, Buffer, sizeof(SvcIdentity));
676 
677     // send sync to server
678     (void)DoSend(ioPtr, BUFFER_TYPE, false);
679 
680     // send async to server
681     (void)DoSend(ioPtr, BUFFER_TYPE, true);
682     RPC_LOG_INFO("[ipc_test_client] ------ SendBuffer end ------");
683     return;
684 }