0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 void do_thread_work ( void *ptr )
0056 {
0057
0058 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0059 long rsplen;
0060 int i;
0061 int ret=EXSUCCEED;
0062 double d;
0063 double dv = 55.66;
0064 int cd;
0065 long revent;
0066 int received = 0;
0067 char tmp[126];
0068
0069
0070 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0071 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0072 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0073
0074
0075 if (EXFAIL==(cd=tpconnect((char *)ptr, (char *)p_ub, 0L, TPRECVONLY)))
0076 {
0077 NDRX_LOG(log_error, "TESTSV connect failed!: %s",
0078 tpstrerror(tperrno));
0079 ret=EXFAIL;
0080 goto out;
0081 }
0082
0083
0084 NDRX_LOG(log_debug, "About to tprecv!");
0085
0086 while (EXSUCCEED==tprecv(cd, (char **)&p_ub, 0L, 0L, &revent))
0087 {
0088 received++;
0089 NDRX_LOG(log_debug, "MSG RECEIVED OK!");
0090 }
0091
0092
0093
0094 if (TPEEVENT==tperrno)
0095 {
0096 received++;
0097 sprintf(tmp, "CLT: %d", received);
0098
0099 Badd(p_ub, T_STRING_FLD, tmp, 0L);
0100 if (TPEV_SENDONLY==revent)
0101 {
0102 int i=0;
0103
0104 for (i=0; i<100 && EXSUCCEED==ret; i++)
0105 {
0106 ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
0107 }
0108 }
0109 }
0110
0111
0112 if (EXFAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
0113 {
0114 NDRX_LOG(log_debug, "TESTERROR: Failed to give server control!!");
0115 ret=EXFAIL;
0116 goto out;
0117 }
0118
0119 NDRX_LOG(log_debug, "Get response from tprecv!");
0120 Bfprint(p_ub, stderr);
0121
0122
0123 ret=tprecv(cd, (char **)&p_ub, 0L, 0L, &revent);
0124 NDRX_LOG(log_error, "tprecv failed with revent=%ld", revent);
0125
0126 if (EXFAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
0127 {
0128 NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
0129 ret=EXSUCCEED;
0130 }
0131
0132 if (EXSUCCEED!=tpterm())
0133 {
0134 NDRX_LOG(log_error, "TESTERROR: tpterm failed with: %s", tpstrerror(tperrno));
0135 ret=EXFAIL;
0136 goto out;
0137 }
0138
0139 out:
0140
0141 NDRX_LOG(log_error, "Thread returns with %d", ret);
0142
0143 }
0144
0145
0146
0147
0148 int main(int argc, char** argv)
0149 {
0150 int j;
0151 pthread_t thread1, thread2, thread3, thread4, thread5;
0152 void *arg1 = "CONVSV";
0153 void *arg2 = "CONVSV2";
0154 void *arg3 = "CONVSV";
0155 void *arg4 = "CONVSV2";
0156 void *arg5 = "CONVSV";
0157
0158 tpinit(NULL);
0159
0160
0161 pthread_create (&thread1, NULL, (void *) &do_thread_work, arg1);
0162 pthread_create (&thread2, NULL, (void *) &do_thread_work, arg2);
0163
0164 pthread_create (&thread3, NULL, (void *) &do_thread_work, arg3);
0165 pthread_create (&thread4, NULL, (void *) &do_thread_work, arg4);
0166 pthread_create (&thread5, NULL, (void *) &do_thread_work, arg5);
0167
0168
0169
0170
0171 pthread_join(thread1, NULL);
0172 pthread_join(thread2, NULL);
0173 pthread_join(thread3, NULL);
0174 pthread_join(thread4, NULL);
0175 pthread_join(thread5, NULL);
0176
0177
0178
0179 exit(0);
0180 }
0181
0182