Tmax Programming Guide ( UCS ) Tmax 38 Tmax Programming Guide (UCS)

Similar documents
Microsoft Word - Tmax Programming Guide _ UCS _.doc

PowerPoint 프레젠테이션

목차 1. 환경변수 OS별환경변수설정 ESQL 시작 ESQL 프로그램생성젃차 오라클 Pro*C 젂환 Precompiler 변경 확장자 *.pc를 *.tbc로변경

13주-14주proc.PDF

6주차.key

Tmax COBOL Guide : TMCG : Tmax 3.8 : July 31, 2003 : Sep 20, 2003

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

PowerPoint 프레젠테이션

untitled

vi 사용법

슬라이드 1

K&R2 Reference Manual 번역본

JEUS WebT Copyright 2004 Tmax Soft Co., Ltd. All Rights Reserved.

chap7.key

Tmax FDL Reference Manual : TMFR : Tmax 3.8 : Sep 20, 2003 : Sep 20, 2003

SYN flooding

제1장 Unix란 무엇인가?

제1장 Unix란 무엇인가?

PowerPoint 프레젠테이션

2009년 상반기 사업계획

PowerPoint 프레젠테이션


Microsoft PowerPoint - 09-Pipe

Microsoft PowerPoint - lab14.pptx

Tmax Getting Started Guide Tmax 3.8 Tmax Getting Started Guide

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

본 강의에 들어가기 전

<43B7CE20BECBBEC6BAB8B4C220BCD2C4CFC7C1B7CEB1D7B7A1B9D62E687770>

Sena Technologies, Inc. HelloDevice Super 1.1.0

[ 목차 ] 1. 취약점개요 2. 배경지식 3. 취약점발생결과 (exploit 테스트 ) 4. 취약점발생원인분석 4.1 취약점 Q&A 5. exploit 분석 6. 보안대책 7. 결론 8. 레퍼런스 2

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

강의10

The Pocket Guide to TCP/IP Sockets: C Version

Microsoft Word - Network Programming_NewVersion_01_.docx

PowerPoint 프레젠테이션

10.

PowerPoint 프레젠테이션

목차 BUG offline replicator 에서유효하지않은로그를읽을경우비정상종료할수있다... 3 BUG 각 partition 이서로다른 tablespace 를가지고, column type 이 CLOB 이며, 해당 table 을 truncate

제1장 Unix란 무엇인가?

1장. 유닉스 시스템 프로그래밍 개요

Microsoft Word - KPMC-400,401 SW 사용 설명서

Microsoft PowerPoint - 13 ¼ÒÄÏÀ» ÀÌ¿ëÇÑ Åë½Å 2.ppt

3. 다음장에나오는 sigprocmask 함수의설명을참고하여다음프로그램의출력물과그출력물이화면이표시되는시점을예측하세요. ( 힌트 : 각줄이표시되는시점은다음 6 가지중하나. (1) 프로그램수행직후, (2) 5 초후 (3) 10 초후 (4) 15 #include <signa

PowerPoint 프레젠테이션

歯9장.PDF

1217 WebTrafMon II

PowerPoint 프레젠테이션

C++-¿Ïº®Çؼ³10Àå

교육지원 IT시스템 선진화

untitled

/chroot/lib/ /chroot/etc/

학번 : 이름 1. 다음프로그램실행결과를예측하시오. $./a.out & [1] 7216 $ kill -USR $ kill -USR 아래학생이작성한쓰레드코드의문제점을설명하시오. void* thread_main() { pthread_mutex_t

ORANGE FOR ORACLE V4.0 INSTALLATION GUIDE (Online Upgrade) ORANGE CONFIGURATION ADMIN O

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

Microsoft PowerPoint - Lecture_Note_5.ppt [Compatibility Mode]

SRC PLUS 제어기 MANUAL

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

0x00 Contents 0x About Nickster 0x Analaysis 0x Exploit

Microsoft PowerPoint - 12 ¼ÒÄÏÀ» ÀÌ¿ëÇÑ Åë½Å 1.ppt

The Pocket Guide to TCP/IP Sockets: C Version

<4D F736F F F696E74202D20B8AEB4AABDBA20BFC0B7F920C3B3B8AEC7CFB1E22E BC8A3C8AF20B8F0B5E55D>

untitled

untitled

untitled

Chap06(Interprocess Communication).PDF

PowerPoint 프레젠테이션

03장.스택.key

제1장 Unix란 무엇인가?

기타자료.PDF

제12장 파일 입출력

PCServerMgmt7

슬라이드 1

MPLAB C18 C

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

3. 다음장에나오는 sigprocmask 함수의설명을참고하여다음프로그램의출력물과그출력물이화면이표시되는시점을예측하세요. ( 힌트 : 각줄이표시되는시점은다음 4 가지중하나. (1) 프로그램수행직후, (2) kill 명령실행직후, (3) 15 #include <signal.

MySQL-Ch10

<4D F736F F F696E74202D20C1A63132B0AD20B5BFC0FB20B8DEB8F0B8AEC7D2B4E7>

untitled

Solaris Express Developer Edition

<4D F736F F F696E74202D E20B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D62E >

untitled

untitled

T100MD+

USB USB DV25 DV25 REC SRN-475S REC SRN-475S LAN POWER LAN POWER Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl C

PowerPoint 프레젠테이션

MAX+plus II Getting Started - 무작정따라하기

PowerPoint 프레젠테이션

SMB_ICMP_UDP(huichang).PDF

Microsoft PowerPoint - 06-CompSys-16-Socket.ppt

<4D F736F F D2034C0E52D554E495820BCD2C4CF20C0C0BFEB20C7C1B7CEB1D7B7A1B9D6>

Microsoft PowerPoint - ch09_파이프 [호환 모드]

2009년 상반기 사업계획

Microsoft PowerPoint - lab15.pptx

PowerPoint 프레젠테이션

Microsoft Word - Tmax Application Development Guide.doc

PWR PWR HDD HDD USB USB Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl Cable PC PC DDNS (

PowerPoint 프레젠테이션

Microsoft PowerPoint - 15-EmbedSW-10-Socket

5.스택(강의자료).key

Transcription:

Tmax Programming Guide ( UCS ) : TMUCS-0219-03-380 : Tmax 38 : FEB 19, 2003 : SEP 20, 2003

Tmax Programming Guide ( UCS ) Tmax 38 Tmax Programming Guide (UCS)

Copyright (c) 2001 Tmax Soft Co, Ltd All Rights Reserved,,, Tmax Soft,,, Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne Tmax Soft Co, Ltd Tmax 135-708 946-1 18 Tel: +82-2-6288-2114, 2006 Fax: +82-2-6288-2115 E-Mail: info@tmaxcokr Tmax UCS Manual Document Edition Date Version TMUCS-0901-03-380 JUL 5, 2001 Tmax 38 Tmax Tmax Base, Tmax Standard, Options Tmax Standard Tmax Standard Tmax Options TP Function + 2 Phase Commit Web Admin Console, X25 Gateway, TCP/IP Gateway, Host-Link, Power Builder Interface Module, SERIAL Gateway, TCP/IP Service Gateway Tmax Programming Guide (UCS)

Tmax UCS Manual / UCS(User Control Server) RDP(Realtime Data Procesor) API UCS/RDP / (TCS ) UCS/RDPTCS Tmax system? Server, Database System Sample? 1 : Tmax UCS/RDP,, 2 : UCS/RDP, 3 : UCS UCS 4 Sample: UCS Client Server Sample Tmax Getting Started Guide Tmax Programming Guide ( C ) Tmax Reference Manual Tmax Programming Guide (UCS)

[ ] ( ) Numeric String Literal abc abc Tmax Programming Guide (UCS)

1 UCS (User Control Server) RDP(Real Data Processor) 8 11 Process Control 8 111 TCS (Tmax Control Server) 8 112 POD(Process On Demand) 9 113 UCS (User Control Server) 9 12 UCS 11 13 RDP(Real Data Processor) 12 2 UCS 13 21 UCS 15 211 UCS Server Program 15 212 UCS Client Program 31 213 RDP Server Program 34 3 UCS 35 31 UCS 35 32 RDP 36 33 UCS 37 34 RDP 39 4 UCS 41 41 (core) 41 42 socket 46 43 RQ 52 5 54 51 UCS 54 52 UCS 55 521 UCS 55 522 UCS 61 53 RDP 69 531 RDP 69 54 UCS 76 tpclrfd 76 tpissetfd 77 tpgetunsol 78 tppost 80 tpregcb 81 tprelay 82 tpsavectx 83 tpschedule 84 tpsendtocli 85 tpsetfd 87 Tmax Programming Guide (UCS)

tpsetunsol 88 tpsetunsol_flag 89 tpsubscribe 90 tpsvctimeout 92 tpsvrdown 93 tpunregcb 94 tpunsubscribe 95 tpuschedule 96 Tmax Programming Guide (UCS)

Tmax Programming Guide ( UCS ) Tmax Programming Guide (UCS)

1 UCS (User Control Server) RDP(Real Data Processor) UCS (User Control Server),, User Tmax UCS, UCS ( ), (UCS ), (, notify),, 11 Process Control TmaxTCS(Tmax Control Server) TypeUCS(User Control Server) Type Process Control TmaxTCS(Tmax Contorl Server), POD(Process On Demand) UCS(User Control Server) TypeProcess Control TCS Middleware(Tuxedo, Entera, TopEnd) request Process Control, POD request Process Control UCSTCS, POD Process Control Process Control TCS, POD Process UCS Process request, UCSTP MonitorTmax 111 TCS (Tmax Control Server) TCS Process 3-Tier Server Process Tmax System request Server ProcessService, Server ProcessService TCS TypeServer Program Tmax Programming Guide (UCS)

main() Signal tpsvrinit() ( ) request requestuser tpsvrdone() User 112 POD(Process On Demand) POD ProcessTCS Process Tmax Tmax 113 UCS (User Control Server) TCS Process, request Process UCS Process request,, request UCS TypeServer Program main() Signal tpsvrinit() usermain() tpsvrdone() usermain() Tmax Programming Guide (UCS)

( ) tpschedule() : : Request User Tmax Programming Guide (UCS)

12 UCS UCS UserControl Server,, (,, )UCS Tmax ( ) UCS, ( ) 1),,, 2) software, end user 3), ( ) 1) batch, 1), (, check looping CPU, ) UCS Type UCS, Tmax Programming Guide (UCS)

13 RDP(Real Data Processor) RDPUCS RDP UCS RDPCLH UCS RDP RDP RDP (RSCPC) CLHRDP ( MINMAX ) RDP MIN, MAXCLH 2 CLHMINCLH, MAXCLH Tmax Programming Guide (UCS)

2 UCS UCS Programusermain, UCS Library (libsvrucsa / libsvrucsso) usermain() loop, usermain() ( ), tpsvrdone(), usermain() main() (main() ) UCS Program usermain() loop tpschedule() tpschedule() tmax kernel usermain() +1 #include <stdioh> +2 #include <usrinc/atmih> +3 #include <ucrinc/ucsh> +4 +5 #define MAX_CLI 10 +6 int num_cli; +7 int client_id[max_cli]; +8 int count; +9 +10 int +11 tpsvrinit(int argc, char *argv[]) +12 +13 num_cli = 0; +14 count = 0; +15 +16 +16 int +17 usermain(int argc, char *argv[]) /* tmaxucs main */ +18 +19 int jobs; +20 int i; +21 int ret; +22 char *sndbuf; +23 static int count = 0; +24 +25 printf("usermain start\n"); +26 +27 sndbuf = (char *)tpalloc("carray", NULL, 1024); +28 +29 while(1) +30 for (i = 0; i < num_cli; i++) +31 sprintf(sndbuf, "Success tpsendtocli [%d] 012345678901234\n", count); +32 tpsendtocli (client_id[i], sndbuf, 1024, 0); +33 +34 count++; +35 sleep(1); +36 jobs = tpschedule(-1); Tmax Programming Guide (UCS)

+37 +38 +39 +40 LOGIN(TPSVCINFO *msg) /* tmaxservice */ +41 +42 char *sndbuf; +43 int clid; +44 int ret; +45 int i; +46 +47 printf("msg->data = [%*s]\n", msg->len, msg->data); +48 fflush(stdout); +49 +50 sndbuf = (char *)tpalloc("carray", NULL, 1024); +51 +52 printf("success transaction"); +53 sprintf(sndbuf, "Success transaction"); +54 +55 if (num_cli < MAX_CLI) +56 client_id[num_cli] = tpgetclid(); +57 printf("client id(clid) = %d\n", client_id[num_cli]); +58 num_cli++; +59 +60 +61 tpreturn(tpsuccess, 0, (char *)sndbuf, 1024, 0); +62 (1) tpsvrinit() usermain() (2) 30, num_cli 0, for (3) 36, tpschedule(), tmdown check (4), LOGIN SERVICE 40 tpschedule() (5) 56, tpgetclid() client global client_id num_cli (6) 61, LOGIN SERVICE (7) 36, tpschedule() (8) 30, num_cli for (9) 32, tpsendtocli() client_id ( ) (10) (3) ~ (9) (11) tpschedule() tmdown, tpsvrdone() Tmax Programming Guide (UCS)

21 UCS 211 UCS Server Program UCS Server Program $(TMAXDIR)/lib/libsvrucsa $(TMAXDIR)/lib/shared/libsvrucsso - Programmain() ucs api - UCS Program make link int tpsvrinit(int argc, char *argv[]) - Global, non-xa int tpsvrdone() - resource non-xa int usermain(int argc, char *argv[]) - applicationlogic - loop (usermain() return, tpsvrdone() ) - tmdown tpschedule() tpschedule()call, tmdown, tmdown i Tmax Programming Guide (UCS)

, UCS 1 1, usermain() tpschedule() call UCS Program, User, API (APIprototype $(TMAXDIR)/usrinc/ucsh ) APIprototype UCS Program API int tpschedule(int sec) int tpuschedule(int usec) API int tpsendtocli(int clid, char *data, long len, long flags) int tpgetclid(void) Non Tmax API int tpsetfd(void) int tpissetfd(void) int tpclrfd(void) int tpgetctx(ctx_t *ctxp) int tpcancelctx(ctx_t *ctxp) CTX_T *tpsavectx() int tprelay(char *svc, char *data, long len, long flags, CTX_T *ctxp); UCS tpacall( ) callback API int tpregcb(void) int tpunregcb(void) API (1) int tpschedule(int timeout) requesttmdown, timeout timout, -1 1 tperrno (timeout )tperrno 13(TPETIME) : int sec - : - 0 : - -1 : check,, : : - : - -1 :,,, timeout tperrno 13 check Tmax Programming Guide (UCS)

: #include <stdioh> #include <usrinc/atmih> #include <usrinc/ucsh> int tpsvrinit(int argc, char *argv[]) return 1; int tpsvrdone() return 1; int usermain(int argc, char *argv[]) int rcode, i; printf("usermain start\n"); while(1) rcode = tpschedule(1); printf( rcode = %d, i = %d, tperrno = %d\n, rcode, i, tperrno); i++; UCSTEST(TPSVCINFO *msg) /* tmaxservice */ printf( UCSTEST start!!\n ); tpreturn(tpsuccess, 0, msg->data, msg->len, 0); : - request : rcode = -1, i = 0, tperrno = 13 rcode = -1, i = 1, tperrno = 13 rcode = -1, i = 2, tperrno = 13 - request rcode = -1, i = 0, tperrno = 13 rcode = -1, i = 1, tperrno = 13 rcode = -1, i = 2, tperrno = 13 UCSTEST start!! /* request */ rcode =1, i=3, tperrno = 0 /* 1return */ rcode = -1, i = 4, tperrno = 13 (2) int tpuschedule(int usec) Tmax Programming Guide (UCS)

tpschedule(), microsecond (3) int tpsendtocli(int clid, char *data, long len, long flags) clid clid tpgetclid(), tpsendtocli()tpgetclid(),, - int clid : tpgetclid() -char *data : tpalloc - long len : - long flags : flags 0 (Zero), networkbandwidth, fault TPUDP 0 flag, UDP TPFLOWCONTROL, 1 : : - 1 : - -1 :, tperrno error check : #include <stdioh> #include <usrinc/atmih> #include <usrinc/ucsh> int client_id[5]; int usermain(int argc, char *argv[]) int jobs; int i; char *sndbuf; Tmax Programming Guide (UCS)

static int count = 0; printf("usermain start\n"); sndbuf = (char *)tpalloc("carray", NULL, 1024); while(1) for (i = 0; i < 5; i++) if (client_id[i] < 0) continue; sprintf(sndbuf, "Success tpsendtocli [%d] 012345678901234\n", count); tpsendtocli (client_id[i], sndbuf, 1024, 0); count++; jobs = tpschedule(1); CONN_CLI(TPSVCINFO *msg) char *sndbuf; int i; sndbuf = (char *)tpalloc("carray", NULL, 1024); if (sndbuf == NULL) printf( tpalloc fail!!!\n, tperrno); tpreturn(tpfail, -1, NULL, 0, 0); for (i=0; i<5; i++) if (client_id[i] < 0) client_id[i] = tpgetclid(); break; strcpy(sndbuf, connect success!! ); tpreturn(tpsuccess, 0, (char *)sndbuf, strlen(sndbuf), 0); int tpsvrinit(int argc, char *argv[]) for (i=0; i<5; i++) client_id[i] = -1; return 1; int tpsvrdone() (4) int tpgetclid(void) reqeust tmax tpsendtocli() tpsendtocli() argumentclid : Tmax Programming Guide (UCS)

: : request (5) int tpsefd(int fd) tpschedule() Tmax request tmdown check, fd check FD_SET() tpclrfd(), tpissetfd() - int fd : socket fd : - 1 : - -1 :, tperrno check (6) int tpissefd(int fd) fd check FD_ISSET() tpsetfd(), tpclrfd() - int fd : socket fd : - 1 : - -1 :, tperrno check (7) int tpclrfd(int fd) socket fdtpschedule() check FD_CLR() tpsetfd(), tpissetfd() - int fd : socket fd : - 1 : - -1 :, tperrno check #include <stdioh> #include <stdlibh> #include <stringh> #include <unistdh> #include <fcntlh> #include <errnoh> #include <signalh> Tmax Programming Guide (UCS)

#include <sys/typesh> #include <sys/timeh> #include <sys/socketh> #include <sys/unh> #include <netinet/inh> #include <arpa/ineth> #include <netdbh> #include <usrinc/atmih> #include <usrinc/ucsh> #ifndef INADDR_NONE #define INADDR_NONE #endif 0xffffffff #define PORT 9345 #define HOST_ADDR "613332107" #define MAX_BUFFER_LEN 4096 +26 /* ------------------- global variable ------------------------- */ int client_fd = -1; +30 /* -- ---------------- service initial -------------------------- */ int tpsvrinit(int argc, char *argv[]) client_fd = network_connect(host_addr, PORT); if (client_fd > 0) /* connect socket fdtpschedule() */ tpsetfd(client_fd); int tpsvrdone() if (client_fd > 0) /* tpschedule socket fd */ tpclrfd(client_fd); close(client_fd); /* ------------------- main --------------------------------- */ int usermain(int argc, char *argv[]) int n; +56 +57 /* never return */ while(1) if (client_fd < 0) client_fd = network_connect(host_addr, PORT); if (client_fd > 0) tpsetfd(client_fd); else tpschedule(5); continue; Tmax Programming Guide (UCS)

if ((n = tpschedule(0)) < 0) sleep(1); continue; /* socket fddata */ if (tpissetfd(client_fd)) if ((n = request_from_client(client_fd)) < 0) tpclrfd(client_fd); close(client_fd); client_fd = -1; /* end of while */ /* ----------------------- client request --------------------------- */ int request_from_client(int fd) int n, len; char *ptr, buffer[max_buffer_len]; /* read header */ memset(buffer, 0x00, sizeof(buffer)); n = socket_read(fd, buffer, 4); if (n <= 0) return -1; len = atoi(buffer); /* read data */ n = socket_read(fd, &buffer[4], len); if (n <= 0) return -1; sleep(3); len += 4; n = socket_write(fd, buffer, len); return n; /* ------------------- client connect for TCP/IP ------------------ */ int network_connect(char *host, int port) struct sockaddr_in serv_addr; unsigned long inaddr; struct hostent *hp; int i, fd; memset((char *) &serv_addr, 0, sizeof(serv_addr)); serv_addrsin_family = AF_INET; serv_addrsin_port = htons(port); if ((inaddr = inet_addr(host))!= INADDR_NONE) memcpy((char *) &serv_addrsin_addr, (char *) &inaddr, sizeof(inaddr)); Tmax Programming Guide (UCS)

else if ((hp = gethostbyname(host)) == NULL) return -1; memcpy((char *) &serv_addrsin_addr, hp->h_addr, hp->h_length); if ((fd = socket(af_inet, SOCK_STREAM, 0)) < 0) return -1; if (connect(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) return fd; close(fd); return -1; /* ------------------- data read ---------------------------------- */ int socket_read(int fd, char *ptr, int nbytes) int nleft, nread; char *ptr2; ptr2 = (char *)ptr; nleft = nbytes; while (nleft > 0) nread = recv(fd, ptr, nleft, 0); if (nread < 0) if (errno == EINTR) continue; else if (errno == EWOULDBLOCK) return (nbytes - nleft); return(nread); /* error, return < 0 */ else if (nread == 0) break; /* EOF */ nleft -= nread; ptr += nread; return (nbytes - nleft); /* return >= 0 */ /* ------------------- data write --------------------------------- */ int socket_write(int fd, char *ptr, int nbytes) int nleft, nwritten; nleft = nbytes; while (nleft > 0) nwritten = send(fd, ptr, nleft, 0); if (nwritten <= 0) return(nwritten); /* error */ nleft -= nwritten; ptr += nwritten; return(nbytes - nleft); Tmax Programming Guide (UCS)

(8) int tpgetctx(ctx_t *ctxp), client transaction CTX_T structure tpsavectx(), ctxpreferenceuser, library tpgetctx()userreference ctxp tpsavectx(), tpgetctx() tpgetctx() CTX_T * : : - CTX_T *ctxp : client transaction structure - 1 : - -1 :, tperrno check (9) int tpcancelctx(ctx_t *ctxp) library : : - CTX_T *ctxp : client transaction structure - 1 : - -1 :, tperrno check (10) CTX_T *tpsavectx(), client transaction CTX_T structure tpgetctx(), ctxpreferenceuser, library tpsavectx() library reference ctxp tpsavectx(), tpgetctx() : : - CTX_T *ctxp : client transaction structure - NULL : (11) int tprelay(char *svc, char *data, long len, long flags, CTX_T *ctxp) tpforward() UCS tpsavectx() client transaction,, tpsavectx() client transaction UCS Tmax Programming Guide (UCS)

block, tpforward(), tprelay() : - char *svc : service - char *data : - long len : - long flags - CTX_T *ctxp: client transaction structure : - 1 : --1 : #include <stdioh> #include <stdlibh> #include <stringh> #include <unistdh> #include <fcntlh> #include <errnoh> #include <signalh> #include <sys/typesh> #include <sys/timeh> #include <sys/socketh> #include <sys/unh> #include <netinet/inh> #include <arpa/ineth> #include <netdbh> #include <usrinc/atmih> #include <usrinc/ucsh> #ifndef INADDR_NONE #define INADDR_NONE #endif 0xffffffff #define MAX_CLIENT 10 #define PORT 9345 #define MAX_BUFFER_LEN 4096 struct myinfo_t int fd; char unique_id[10]; CTX_T *ctx; ; typedef struct myinfo_t MYINFO; /* ----------------------- global variable ------------------------- */ int listen_fd = -1; Tmax Programming Guide (UCS)

int client_fd = -1; int portno; MYINFO *myinfo; /* ----------------------- service initial -------------------------- */ int tpsvrinit(int argc, char *argv[]) listen_fd = network_listen(portno); if (listen_fd > 0) tpsetfd(listen_fd); client_init(); int tpsvrdone() if (listen_fd > 0) tpclrfd(listen_fd); close(listen_fd); /* ----------------------- client initial --------------------------- */ int client_init() int i, len; len = sizeof(myinfo) * MAX_CLIENT; myinfo = (MYINFO *)malloc(len); for (i = 0; i < MAX_CLIENT; i++) myinfo[i]fd = -1; myinfo[i]ctx = NULL; /* ----------------------- main ------------------------------------- */ int usermain(int argc, char *argv[]) int n; /* never return */ while(1) if (listen_fd < 0) listen_fd = network_listen(port); if (listen_fd > 0) tpsetfd(listen_fd); else tpschedule(5); continue; if ((n = tpschedule(0)) < 0) sleep(1); continue; Tmax Programming Guide (UCS)

/* check listen port */ if (tpissetfd(listen_fd)) if ((client_fd = network_accept(listen_fd)) < 0) tpclrfd(listen_fd); close(listen_fd); listen_fd = -1; else tpsetfd(client_fd); continue; /* check client port */ if (tpissetfd(client_fd)) if (client_response(client_fd) < 0) tpclrfd(client_fd); close(client_fd); client_fd = -1; /* end of while */ /* ----------------------- service ---------------------------------- */ UCS_TEST(TPSVCINFO *msg) int i, n; CTX_T *ctx; printf("ucs_test : 12345\n"); ctx = (CTX_T *)tpsavectx(); for (i = 0; i < MAX_CLIENT; i++) if (myinfo[i]fd < 0) myinfo[i]fd = client_fd; memcpy(myinfo[i]unique_id, msg->data, 6); myinfo[i]ctx = ctx; break; n = message_write(client_fd, msg->data, msg->len); if (n < 0) tpclrfd(client_fd); close(client_fd); client_fd = -1; tpreturn(tpfail, 999, (char *)NULL, 0, 0); tpreturn(tpsuccess, 0, (char *)NULL, 0, 0); /* ----------------------- message write ---------------------------- */ int message_write(int fd, char *data, long datalen) int n, len; Tmax Programming Guide (UCS)

char char buffer[max_buffer_len]; temp[10]; memcpy(&buffer[4], data, datalen); sprintf(temp, "%04d", datalen); memcpy(buffer, temp, 4); len = datalen + 4; n = socket_write(fd, buffer, len); printf("ucs_listen:socket-write = %d\n", n); return n; /* ------------------- client response ---------------------------- */ int client_response(int fd) int i, n, len; CTX_T *ctx; char *ptr, buffer[max_buffer_len]; /* read header */ memset(buffer, 0x00, sizeof(buffer)); n = socket_read(fd, buffer, 4); if (n <= 0) return -1; len = atoi(buffer); printf("ucs_listen:length : %d\n", len); /* client memory alloc */ ptr = (char *)tpalloc("carray", "", len+10); if (ptr == NULL) return -1; /* read data */ n = socket_read(fd, ptr, len); if (n <= 0) tpfree(ptr); return -1; for (i = 0; i < MAX_CLIENT; i++) if (myinfo[i]fd < 0) continue; if (memcmp(myinfo[i]unique_id, ptr, 6) == 0) ctx = myinfo[i]ctx; myinfo[i]fd = -1; myinfo[i]ctx = NULL; break; if (i >= MAX_CLIENT) return 0; printf("ucs_listen:tprelay before: length = %d\n", n); n = tprelay("xa_tolower", ptr, (long)n, 0, ctx); Tmax Programming Guide (UCS)

if (n < 0) printf("ucs_listen:tprelay failed: tperrno=%d\n", tperrno); printf("ucs_listen:tprelay ok\n"); tpfree(ptr); return 0; /* ------------------- server : listen ---------------------------- */ int network_listen(int portno) int fd; int on; struct sockaddr_in serv_addr; if ((fd = socket(af_inet, SOCK_STREAM, 0)) < 0) return(-1); on = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0) printf("setsockopt error for SO_REUSEADDR"); memset((char *) &serv_addr, 0, sizeof(serv_addr)); serv_addrsin_family = AF_INET; serv_addrsin_addrs_addr = htonl(inaddr_any); serv_addrsin_port = htons(portno); if (bind(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) close(fd); return(-2); if (listen(fd, 250) < 0) close(fd); return(-3); return(fd); /* ------------------- server : client accept --------------------- */ int network_accept(int listenfd) int fd, len; struct sockaddr_in cli_addr; len = sizeof(cli_addr); fd = accept(listenfd, (struct sockaddr *)&cli_addr, &len); if (fd < 0) return(-1); /* often errno=eintr, if signal caught */ return(fd); Tmax Programming Guide (UCS)

/* ------------------- data write --------------------------------- */ int socket_write(int fd, char *ptr, int nbytes) int nleft, nwritten; nleft = nbytes; while (nleft > 0) nwritten = send(fd, ptr, nleft, 0); if (nwritten <= 0) return(nwritten); /* error */ nleft -= nwritten; ptr += nwritten; return(nbytes - nleft); /* ------------------- data read ---------------------------------- */ int socket_read(int fd, char *ptr, int nbytes) int nleft, nread; char *ptr2; ptr2 = (char *)ptr; nleft = nbytes; while (nleft > 0) nread = recv(fd, ptr, nleft, 0); if (nread < 0) if (errno == EINTR) continue; else if (errno == EWOULDBLOCK) return (nbytes - nleft); return(nread); /* error, return < 0 */ else if (nread == 0) break; /* EOF */ nleft -= nread; ptr += nread; return (nbytes - nleft); /* return >= 0 */ (11) int tpregcb(void) UCS UCS tpgetreply(), tpacall() tpgetreply() tpregcb() callback : : Tmax Programming Guide (UCS)

- 1 : - -1 : 212 UCS Client Program UCS Program Service Client Program, UCS Program Data, UCS Program Data Client Program UCS Program Data tpsetunsol_flag(), tpsetunsol(), tpgetunsol() tpsetunsol_flag()tpstart() Tmax System flag flag API (1) int tpsetunsol_flag(int flag) flag tpsetunsol_flag()tpstart() Tmax flag flag flagsms TPUNSOL_IGN, TPUNSOL_HND, TPUNSOL_POLL 3 TPUNSOL_IGN flag, TPUNSOL_HNDTPUNSOL_POLL : int flag - TPUNSOL_IGN : - TPUNSOL_HND : - TPUNSOL_POLL : : - 1 : --1 : (2) Unsolfunc tpsetunsol(void (*disp)(char *data, long len, long flags)) tpsetunsol() Tmax tpsetunsol(), Tmax NULL tpsetunsol(), tpsetunsol() data, len flags, datanull Tmax Programming Guide (UCS)

data, data, return : : - : - TPUNSOLERR : (3) int tpgetunsol(int type, char **data, long *len, long flags) tpgetunsol() tpbroadcast() tpsendtocli(), tppost() tpgetunsol() tpgetunsol(), tpstart() Tmax flagstpunsol_polltpunsol_hnd tpgetunsol() tpstart() TPUNSOL_IGN TPUNSOL_POLL : - int type * UNSOL_TPPOST : tppost() * UNSOL_TPBROADCAST : tpbroadcast() * UNSOL_TPSENDTOCLI : tpsendtocli() - int flags * TPBLOCK : * TPNOTIME : : - char **data : - long *len : - 1 : --1: #include <stdioh> #include <usrinc/atmih> #include <usrinc/ucsh> main(int argc, char *argv[]) char *sndbuf; char *rcvbuf; long rcvlen; int RecvCnt = 0; Tmax Programming Guide (UCS)

if(tpstart((tpstart_t *)NULL) == -1) printf("tpstart failed[%s]\n",tpstrerror(tperrno)); exit(-1); tpsetunsol_flag(tpunsol_poll); if((sndbuf = (char *)tpalloc("carray", NULL, 1024)) == NULL) printf("sndbuf failed\n"); tpend(); exit(-1); if((rcvbuf = (char *)tpalloc("carray", NULL, 1024)) == NULL) printf("rcvbuf failed\n"); tpfree((char *)sndbuf); tpend(); exit(-1); if(tpcall("login", sndbuf, 1024, &rcvbuf, &rcvlen, 0) == -1) printf("can't send request to service LOGIN\n"); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); printf("after tpcall() received Message from server:%s\n", rcvbuf); while(1) tpgetunsol(unsol_tpsendtocli, &rcvbuf, &rcvlen, TPBLOCK); printf("loop Count : %d\n", RecvCnt); if(rcvlen > 0) printf("counter : %d #[Received Data from Server : %s]\n ", RecvCnt, rcvbuf); RecvCnt ++; Tmax Programming Guide (UCS)

213 RDP Server Program RDP Server Program UCS Programusermain() application logic RDP Server Program $(TMAXDIR)/lib/libsvrrs so - Programmain() RDP api - RDP Program compile link int tpsvrinit(int argc, char *argv[]) - Global, non-xa int tpsvrdone() - resource non-xa int usermain(int argc, char *argv[]) - applicationlogic - loop (usermain() return, tpsvrdone() ) - UCS Server Program RDP Server Program tpschedule() RDP Client ProgramUCS Client Program tpsetunsol_flag(), tpsetunsol(), tpgetunsol() API 212 UCS Client Program Tmax Programming Guide (UCS)

3 UCS 31 UCS SERVER SVGNAME SVRTYPE UCS UCS *DOMAIN tmax1 *NODE tmaxs1 tmaxs2 *SVRGROUP svg1 svg2 *SERVER ucssvr1 ucssvr2 *SERVICE SVC1 SHMKEY =79970, MINCLH=1, MAXCLH=3, TPORTNO=8844, BLOCKTIME=120, RACPORT=3443 TMAXDIR = "/user1/jaya/tmax3511", APPDIR = "/user1/jaya/tmax3511/appbin", PATHDIR = "/user1/jaya/tmax3511/path", TLOGDIR = "/user1/jaya/tmax3511/log/tlog", ULOGDIR = "/user1/jaya/tmax3511/log/ulog", SLOGDIR = "/user1/jaya/tmax3511/log/slog" TMAXDIR = "/user/jaya/tmax3511", APPDIR = "/user/jaya/tmax3511/appbin", PATHDIR = "/user/jaya/tmax3511/path", TLOGDIR = "/user/jaya/tmax3511/log/tlog", ULOGDIR = "/user/jaya/tmax3511/log/ulog", SLOGDIR = "/user/jaya/tmax3511/log/slog" NODENAME = "tmaxs1" NODENAME = "tmaxs2" SVGNAME = svg1, SVRTYPE = UCS, CPC = 5 SVGNAME = svg2, SVRTYPE = UCS # UCSCLH # UCS TCS TypeService SVRNAME = ucssvr1 Tmax Programming Guide (UCS)

32 RDP RDP DOMAINMINCLH MAXCLH NODE REALSVR Real Server rscpc Real Server Real Server Real Server Real Server Channel rscpc SERVER MINMAX DOMAIN MINCLHMAXCLH ( 2 ) SVRTYPE=REALSVR *DOMAIN tmax1 *NODE tmaxi1 SHMKEY =70990, MINCLH=2, MAXCLH=2 TMAXDIR = "/home/navis/tmax", APPDIR = "/home/navis/tmax/appbin", PATHDIR = "/home/navis/tmax/path", TLOGDIR = "/home/navis/tmax/log/tlog", ULOGDIR = "/home/navis/tmax/log/ulog", SLOGDIR = "/home/navis/tmax/log/slog", REALSVR = real", rscpc = 16 *SVRGROUP svg1 svg2 NODENAME = "tmaxi1" NODENAME = "tmaxi1" *SERVER deal real SVGNAME = svg2, MIN=1 SVGNAME = svg1, MIN=1, MAX=1, SVRTYPE = REALSVR, *SERVICE IN OUT SVRNAME = deal SVRNAME = deal Tmax Programming Guide (UCS)

33 UCS UCS Server Program UCS Library(libsvrucsa libsvrucsso) $TMAXDIR/usrinc/ucsh include, Makefile TMAXLIBS -lsvrucs UCS Server ProgramMakefile ( OS32bit Solaris, OS Makefile ) # Server makefile TARGET = $(COMP_TARGET) APOBJS = $(TARGET)o SDLFILE = demos #Solaris LIBS = -lsvrucs -lsocket lnsl -nodb # OS #LIBS = -lsvrucs -nodb OBJS = $(APOBJS) $(SDLOBJ) $(SVCTOBJ) SDLOBJ = $SDLFILE:s=_sdlo SDLC = $SDLFILE:s=_sdlc SVCTOBJ = $(TARGET)_svctabo CFLAGS = -O -I$(TMAXDIR) APPDIR = $(TMAXDIR)/appbin SVCTDIR = $(TMAXDIR)/svct LIBDIR = $(TMAXDIR)/lib # SUFFIXES : c co: $(CC) $(CFLAGS) -c $< # # server compile # $(TARGET): $(OBJS) $(CC) $(CFLAGS) -L$(LIBDIR) -o $(TARGET) $(OBJS) $(LIBS) mv $(TARGET) $(APPDIR)/ rm -f $(OBJS) Tmax Programming Guide (UCS)

$(APOBJS): $(TARGET)c $(CC) $(CFLAGS) -c $(TARGET)c $(SVCTOBJ): touch $(SVCTDIR)/$(TARGET)_svctabc $(CC) $(CFLAGS) -c $(SVCTDIR)/$(TARGET)_svctabc $(SDLOBJ): $(TMAXDIR)/bin/sdlc -i /sdl/$(sdlfile) $(CC) $(CFLAGS) -c /sdl/$(sdlc) # clean: -rm -f *o core $(TARGET) Tmax Programming Guide (UCS)

34 RDP RDP Server Program RDP Library(libsvrrsso) $TMAXDIR/usrinc/ucsh include, Makefile TMAXLIBS lsvrrs lpthread RDP Server ProgramUCS Makefile ( OS32bit Solaris, OS Makefile ) # Server makefile TARGET = $(COMP_TARGET) APOBJS = $(TARGET)o SDLFILE = demos #Solaris LIBS = -lsvrrs -lpthread -lnodb -lsocket -lnsl OBJS = $(APOBJS) $(SDLOBJ) $(SVCTOBJ) SDLOBJ = $SDLFILE:s=_sdlo SDLC = $SDLFILE:s=_sdlc SVCTOBJ = $(TARGET)_svctabo CFLAGS = -O -I$(TMAXDIR) APPDIR = $(TMAXDIR)/appbin SVCTDIR = $(TMAXDIR)/svct LIBDIR = $(TMAXDIR)/lib # SUFFIXES : c co: $(CC) $(CFLAGS) -c $< # # server compile # $(TARGET): $(OBJS) $(CC) $(CFLAGS) -L$(LIBDIR) -o $(TARGET) $(OBJS) $(LIBS) mv $(TARGET) $(APPDIR)/ rm -f $(OBJS) $(APOBJS): $(TARGET)c Tmax Programming Guide (UCS)

$(CC) $(CFLAGS) -c $(TARGET)c $(SVCTOBJ): touch $(SVCTDIR)/$(TARGET)_svctabc $(CC) $(CFLAGS) -c $(SVCTDIR)/$(TARGET)_svctabc $(SDLOBJ): $(TMAXDIR)/bin/sdlc -i /sdl/$(sdlfile) $(CC) $(CFLAGS) -c /sdl/$(sdlc) # clean: -rm -f *o core $(TARGET) Tmax Programming Guide (UCS)

4 UCS UCS UCS 41 (core) ucs_svr1c (core) file directory move #include <stdioh> #include <stdlibh> #include <unistdh> #include <timeh> #include <sys/timeh> #include <sys/typesh> #include <direnth> #include <fcntlh> #include <usrinc/atmih> char _file_path[100]; int _cliid[10]; int tpsvrint(int argc, char *argv[]) return 0; int tpsvrdone() return 0; int usermain(int argc, char *argv[]) int iret, i; char core_file[50]; char server_name[50]; Tmax Programming Guide (UCS)

char cur_time[20]; char *str; /* init cliid */ for (i=0; i<10; i++) _cliid[i] = -1; strcpy(_file_path, argv[1]); sprintf(core_file, "%s/core", _file_path); while(1) tpschedule(5); iret = checkcorefile(); if (iret == 1) iret = getcorename(core_file, server_name); iret = getcurrenttime(cur_time); iret = movecorefile(core_file, server_name, cur_time); str = (char *)tpalloc("string", NULL, 0); sprintf(str, "%s program core!!", server_name); for (i=0; i<10; i++) if (_cliid[i] < 0) continue; iret = tpsendtocli(_cliid[i], str, strlen(str), 0); if (iret == -1) printf("client close connect!!\n"); _cliid[i] = -1; for (i=0; i<10; i++) printf("cliid = %d - %d\n", i, _cliid[i]); tpfree(str); int checkcorefile() char server_name[50]; char core_file[100]; struct dirent *dirent; DIR *dp; Tmax Programming Guide (UCS)

dp = opendir(_file_path); if (dp == NULL) printf("%s directory is not found!\n", _file_path); return -1; for (dirent = readdir(dp); dirent!= NULL; dirent = readdir(dp)) if ( (strlen(dirent->d_name) == 4) && (strncmp(dirent->d_name, "core", 4) == 0)) closedir(dp); return 1; closedir(dp); return -1; int getcorename(char *filename, char *server) int fd, cnt, i; char buf[6000]; fd = open(filename, O_RDONLY); #ifdef _HP cnt = read(fd, buf, 144); #endif #ifdef _SUN cnt = read(fd, buf, 132); #endif #ifdef _IBM cnt = read(fd, buf, 1759); #endif cnt = read(fd, buf, 1760); while(1) cnt = read(fd, buf, 1); if (cnt!= 1) return -1; *server++ = buf[0]; if (buf[0] == 0) break; Tmax Programming Guide (UCS)

close(fd); int getcurrenttime(char *cur_time) struct tm *tm; time_t tnow; time(&tnow); tm = localtime(&tnow); sprintf(cur_time, "%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return 0; int movecorefile(char *core, char *server, char *time) char cmd[100]; char file_name[50]; printf("server = [%s]\n", server); sprintf(file_name, "core_%s_%s", server, time); sprintf(cmd, "mv %s %s/%s", core, _file_path, file_name); system(cmd); return 0; CONN_TERM(TPSVCINFO *msg) int i; char *stdata; stdata = (char *)msg->data; for (i=0; i<10; i++) if (_cliid[i] >= 0) continue; _cliid[i] = tpgetclid(); printf("connect client %d = %d\n", i, _cliid[i]); Tmax Programming Guide (UCS)

break; tpreturn(tpsuccess, 0, (char *)stdata, 0, 0); Tmax Programming Guide (UCS)

42 socket ucs_svr2c client socketaccept, acceptsocket tpacall client ucs_svr2c usermain() #include <stdioh> #include <stdlibh> #include <stringh> #include <unistdh> #include <fcntlh> #include <errnoh> #include <signalh> #include <sys/typesh> #include <sys/timeh> #include <sys/socketh> #include <sys/unh> #include <netinet/inh> #include <arpa/ineth> #include <netdbh> #include <usrinc/atmih> #include <usrinc/ucsh> #ifndef INADDR_NONE #define INADDR_NONE #endif 0xffffffff #define CLIENT_PORT 9345 #define HOST_ADDR "613332107" #define MAX_BUFFER_LEN 4096 /* ----------------------- global variable --------------------------- */ int client_fd = -1; char ip_addr[30]; int portno; extern int _cur_clhfd; /* ----------------------- service initial -------------------------- */ tpsvrinit(int argc, char *argv[]) sleep(5); parse_args(argc, argv); Tmax Programming Guide (UCS)

client_fd = network_connect(ip_addr, portno); if (client_fd > 0) tpsetfd(client_fd); printf("ucs_sample:client_fd = %d\n", client_fd); printf("ucs_sample: _cur_clhfd(1) = %d\n", _cur_clhfd); tpsvrdone() if (client_fd > 0) tpclrfd(client_fd); close(client_fd); /* ----------------------- main ------------------------------------- */ int usermain(int argc, char *argv[]) int n; /* never return */ while(1) if (client_fd < 0) client_fd = network_connect(ip_addr, portno); if (client_fd > 0) tpsetfd(client_fd); else tpschedule(5); continue; printf("ucs_sample:client_fd = %d\n", client_fd); printf("ucs_sample: _cur_clhfd(1) = %d\n", _cur_clhfd); if ((n = tpschedule(0)) < 0) sleep(1); continue; printf("ucs_sample: _cur_clhfd(2) = %d\n", _cur_clhfd); if (tpissetfd(client_fd)) if ((n = request_from_client(client_fd)) < 0) Tmax Programming Guide (UCS)

tpclrfd(client_fd); close(client_fd); client_fd = -1; /* ----------------------- command argument ------------------------- */ int parse_args(int argc, char *argv[]) int c; portno = -1; memset(ip_addr, 0x00, sizeof(ip_addr)); opterr = 0; /* don't want getopt() writing to stderr */ while ((c = getopt(argc, argv, "i:p:"))!= EOF) switch (c) case 'p': /* port */ portno = atoi(optarg); break; case 'i': /* ip-addr */ strcpy(ip_addr, optarg); break; case '?': printf("unrecognized option: -%c", optopt); /* default value: portno, shared memory key */ if (portno <= 0) portno = CLIENT_PORT; printf("no PORT is set: assumed %d\n", portno); if (ip_addr[0] == 0x00) strcpy(ip_addr, HOST_ADDR); printf("no IP-ADDR is set: assumed %s\n", ip_addr); return 1; Tmax Programming Guide (UCS)

/* ----------------------- client request --------------------------- */ int request_from_client(int fd) int n, len; char *ptr, buffer[max_buffer_len]; /* read header */ memset(buffer, 0x00, sizeof(buffer)); n = socket_read(fd, buffer, 4); if (n <= 0) return -1; len = atoi(buffer); printf("ucs_sample:length : %d\n", len); /* read data */ n = socket_read(fd, &buffer[4], len); if (n <= 0) return -1; sleep(3); len += 4; n = socket_write(fd, buffer, len); printf("ucs_sample:socket write : n=%d\n", n); return n; /* ------------------- client connect for TCP/IP ------------------ */ int network_connect(char *host, int port) struct sockaddr_in serv_addr; unsigned long inaddr; struct hostent *hp; int i, fd; memset((char *) &serv_addr, 0, sizeof(serv_addr)); serv_addrsin_family = AF_INET; serv_addrsin_port = htons(port); /* First try to convert the host name as a dotted-decimal number * Only if that fails do we call gethostbyname() */ if ((inaddr = inet_addr(host))!= INADDR_NONE) Tmax Programming Guide (UCS)

/* it's dotted-decimal */ memcpy((char *) &serv_addrsin_addr, (char *) &inaddr, sizeof(inaddr)); else if ((hp = gethostbyname(host)) == NULL) printf("host name error: %s\n", host); return(-1); memcpy((char *) &serv_addrsin_addr, hp->h_addr, hp->h_length); if ((fd = socket(af_inet, SOCK_STREAM, 0)) < 0) printf("can't open stream socket\n"); return -1; if (connect(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) return fd; close(fd); return -1; /* ------------------- data read ---------------------------------- */ int socket_read(int fd, char *ptr, int nbytes) int nleft, nread; char *ptr2; ptr2 = (char *)ptr; nleft = nbytes; while (nleft > 0) nread = recv(fd, ptr, nleft, 0); if (nread < 0) if (errno == EINTR) continue; else if (errno == EWOULDBLOCK) return (nbytes - nleft); return(nread); /* error, return < 0 */ else if (nread == 0) break; /* EOF */ nleft -= nread; ptr += nread; Tmax Programming Guide (UCS)

return (nbytes - nleft); /* return >= 0 */ /* ------------------- data write --------------------------------- */ int socket_write(int fd, char *ptr, int nbytes) int nleft, nwritten; nleft = nbytes; while (nleft > 0) nwritten = send(fd, ptr, nleft, 0); if (nwritten <= 0) return(nwritten); /* error */ nleft -= nwritten; ptr += nwritten; return(nbytes - nleft); Tmax Programming Guide (UCS)

43 RQ ucs_svr3c fail queue datadequeue call #include <sys/typesh> /* required for some of our prototypes */ #include <stdioh> #include <stdlibh> #include <stringh> #include <unistdh> #include <fcntlh> #include #include #include #include #include #include #include <sys/socketh> <sys/stath> <sys/unh> <netinet/inh> <arpa/ineth> <usrinc/atmih> <usrinc/tmaxapih> #define MAX_BUF_SZ 10000 #define SZ 100 #define QUEFILE "rq1" #define QUESERVICE "+fail" int usermain(int argc, char*argv[]) char svc[xatmi_service_name_length]; long len, n; int try, ifailcnt; char *ptr; char QueFile[SZ]; char QueService[SZ]; strcpy(quefile, QUEFILE); strcpy(queservice, QUESERVICE); ptr = (char *)tpalloc("carray", NULL, MAX_BUF_SZ); while (1) /* Endless Loop */ tpschedule(10); /* Sleep 10 seconds */ n = 0; Tmax Programming Guide (UCS)

try = 0; ifailcnt = tpqstat(quefile, TMAX_FAIL_QUEUE); #ifdef _DEBUG printf("\ntpqstat FailCount value = [%d]\n", ifailcnt); #endif while( (n >= 0) && (try++ < ifailcnt ) ) n = tpdeq(quefile, QueService, &ptr, &len, TPRQS ); #ifdef _DEBUG printf("tpdeq n value = [%s] \n", tpstrerror(n)); #endif if (n < 0 ) if (tperrno == TPEMATCH) /* Fail Q empty */ ; else printf("tpdeq fail[%s]\n", tpstrerror(tperrno)); continue; n = tpextsvcname((char*)ptr, svc); #ifdef _DEBUG printf("tpextsvcname value = [%s]\n", svc); #endif if (n < 0) printf("tpextsvcname fail![%s]\n", tpstrerror(tperrno)); continue; n = tpenq(quefile, svc, (char*)ptr, len, TPRQS); #ifdef _DEBUG printf("tpenq n value = [%d]\n", n); #endif if (n < 0) printf("tpenq fail![%s]\n", tpstrerror(tperrno)); continue; return 1; Tmax Programming Guide (UCS)

5 51 UCS UCS UCS * -- RQ Tmax * POS -- RQ DB * -- FireWall Disconnect, Applet Connect Tmax LOGIN Heart Bit Session * HTS ( ) -- * ARS requestsocket Tmax call -- ARS TCP/IP, ARS MessageTmax Server ARS * ServerTCP/IP, RQ UCS Tmax Programming Guide (UCS)

52 UCS 521 UCS UCS Loop LOGIN UCS Config File *DOMAIN tmax1 SHMKEY =79970, MINCLH=1, MAXCLH=3, TPORTNO=8844, BLOCKTIME=120 *NODE tmaxs2 TMAXDIR = "/user/jaya/tmax3511", APPDIR = "/user/jaya/tmax3511/appbin", PATHDIR = "/user/jaya/tmax3511/path", TLOGDIR = "/user/jaya/tmax3511/log/tlog", ULOGDIR = "/user/jaya/tmax3511/log/ulog", SLOGDIR = "/user/jaya/tmax3511/log/slog" *SVRGROUP tmaxs2_nx NODENAME = "tmaxs2" *SERVER ucs_server SVGNAME = tmaxs2_nx, SVRTYPE = UCS *SERVICE LOGIN SVRNAME = ucs_server Client Program Client Program tpstart() LOGIN tpcall(), UCS Client Program tpsetunsol_flag(tpunsol_poll); Client Program sndbuf "Client Registration Success" rcvbuf Tmax Programming Guide (UCS)

printf("after tpcall() received Message from server:%s\n", rcvbuf); Client loop count, count for loop sndbuf Success tpsendtocli [0] Client while loop Loop count while(1) tpgetunsol(unsol_tpsendtocli, &rcvbuf, &rcvlen, TPBLOCK); printf("loop Count : %d\n", RecvCnt); if(rcvlen > 0) printf("counter : %d #[Received Data from Server : %s]\n ", RecvCnt, rcvbuf); RecvCnt ++; #include <stdioh> #include <usrinc/atmih> #include <usrinc/ucsh> main(int argc, char *argv[]) char *sndbuf; char *rcvbuf; long rcvlen; int RecvCnt = 0; if(tpstart((tpstart_t *)NULL) == -1) error processing tpsetunsol_flag(tpunsol_poll); if((sndbuf = (char *)tpalloc("carray", NULL, 1024)) == NULL) error processing if((rcvbuf = (char *)tpalloc("carray", NULL, 1024)) == NULL) error processing if(tpcall("login", sndbuf, 1024, &rcvbuf, &rcvlen, 0) == -1) error processing printf("after tpcall() received Message from server:%s\n", rcvbuf); Tmax Programming Guide (UCS)

while(1) tpgetunsol(unsol_tpsendtocli, &rcvbuf, &rcvlen, TPBLOCK); printf("loop Count : %d\n", RecvCnt); if(rcvlen > 0) printf("counter : %d #[Received Data from Server : %s]\n ", RecvCnt, rcvbuf); RecvCnt ++; if (RecvCnt == 10) break; tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); tmaxs2:/user/jaya/tmax3511/sample/client> ucs_client After tpcall() received Message from server:client Registration Success Loop Count : 0 Counter : 0 #[Received Data from Server : Success tpsendtocli [0]] Loop Count : 1 Counter : 1 #[Received Data from Server : Success tpsendtocli [1]] Loop Count : 2 Counter : 2 #[Received Data from Server : Success tpsendtocli [2]] Loop Count : 3 Counter : 3 #[Received Data from Server : Success tpsendtocli [3]] Loop Count : 4 Counter : 4 #[Received Data from Server : Success tpsendtocli [4]] Server Program Server Program Tmax 5 sleep loop execute 0 loop sleep(5); printf ("loop execute %d\n", count); loop while loop jobs = tpschedule(-1);, loop, client_id[num_cli] = tpgetclid(); printf("client id(clid) = %d\n", client_id[num_cli]); num_cli++; Tmax Programming Guide (UCS)

id while loopfor loop count sndbuf tpsendtocli() for (i = 0; i < num_cli; i++) sprintf(sndbuf, "Success tpsendtocli [%d]", count++); /* Client id */ tpsendtocli (client_id[i], sndbuf, 1024, 0); sndbuf tpreturn() sprintf(sndbuf, "Client Registration Success"); tpreturn(tpsuccess, 0, (char *)sndbuf, 1000, 0); #include <stdioh> #include <usrinc/atmih> #include <usrinc/ucsh> #define MAX_CLI 100 int num_cli; int client_id[max_cli]; int count; tpsvrinit(int argc, char *argv[]) num_cli = 0; count = 0; printf("ucs Type Server tpsvrinit() is call\n"); /* tmaxucs main */ int usermain(int argc, char *argv[]) int jobs; int i; int ret; char *sndbuf; static int count = 0; printf("usermain start\n"); sndbuf = (char *)tpalloc("carray", NULL, 1024); while(1) sleep(5); printf ("loop execute %d\n", count); for (i = 0; i < num_cli; i++) sprintf(sndbuf, "Success tpsendtocli [%d]", count++); Tmax Programming Guide (UCS)

/* Client id */ tpsendtocli (client_id[i], sndbuf, 1024, 0); jobs = tpschedule(-1); /* while */ LOGIN(TPSVCINFO *msg) char *sndbuf; int clid; int ret; int i; sndbuf = (char *)tpalloc("carray", NULL, 1024); if (num_cli < MAX_CLI) /* Clientid */ client_id[num_cli] = tpgetclid(); printf("client id(clid) = %d\n", client_id[num_cli]); num_cli++; sprintf(sndbuf, "Client Registration Success"); tpreturn(tpsuccess, 0, (char *)sndbuf, 1000, 0); tpsvrdone() usermain start UCS Type Server tpsvrinit() is call usermain start loop execute 0 loop execute 0 loop execute 0 client id(clid) = 2097152 loop execute 0 loop execute 1 loop execute 2 loop execute 3 loop execute 4 loop execute 5 loop execute 6 loop execute 7 loop execute 8 loop execute 9 loop execute 10 Tmax Programming Guide (UCS)

loop execute 11 loop execute 12 loop execute 13 loop execute 14 client id(clid) = 2097153 loop execute 15 loop execute 17 loop execute 19 Tmax Programming Guide (UCS)

522 UCS 3 UCS Loop, select call insert ucssvrcucs mainsvrpc MAIN tpcall UCS tpcall mainsvrpc test_sel select inssvrpc INS tpcall tpcall inssvrpctest_ins test_sel select insert mainsvrpctx_commit() test_sel inssvrpc delete test_sel 6 6 delete 1403 Config File *DOMAIN tmax1 SHMKEY =79970, MINCLH=1, MAXCLH=3, TPORTNO=8844, BLOCKTIME=120 *NODE tmaxs2 TMAXDIR = "/user/jaya/tmax3511", APPDIR = "/user/jaya/tmax3511/appbin", PATHDIR = "/user/jaya/tmax3511/path", TLOGDIR = "/user/jaya/tmax3511/log/tlog", ULOGDIR = "/user/jaya/tmax3511/log/ulog", SLOGDIR = "/user/jaya/tmax3511/log/slog" *SVRGROUP tmaxs2_nx NODENAME = "tmaxs2" ### tms for Oracle ### Tmax Programming Guide (UCS)

tmaxs2_xa *SERVER ucssvr mainsvr inssvr NODENAME = "tmaxs2", DBNAME = ORACLE, OPENINFO = "Oracle_XA+Acc=P/scott/tiger+SesTm=60", TMSNAME = tms_ora SVGNAME = tmaxs2_nx, SVRTYPE = UCS, MIN = 1 SVGNAME = tmaxs2_xa, MIN = 1 SVGNAME = tmaxs2_xa, MIN = 1 *SERVICE MAIN INS DB Table SQL> select * from test_sel; A -------------------- aaaaa bbbbb ccccc ddddd eeeee fffff SVRNAME = mainsvr SVRNAME = ins 6 rows selected SQL> select * from test_ins; no rows selected Server Program (ucssvrc ) #include <stdioh> #include <usrinc/atmih> #include <unistdh> int usermain(int argc, char *argv[]) /* tmaxucs main */ int ret; Tmax Programming Guide (UCS)

int long char jobs; len; *sndbuf, *rcvbuf; printf("usermain start\n"); sndbuf = (char *)tpalloc("string", NULL, 0); rcvbuf = (char *)tpalloc("string", NULL, 0); while(1) ret = tpcall("main", sndbuf, 0, &rcvbuf, &len, 0); if (ret == -1) error processing jobs = tpschedule(-1); sleep (10); Server Program (mainsvrpc ) #include <stdioh> #include <ctypeh> #include <usrinc/atmih> EXEC SQL include sqlcah; #define MAXROW 6 EXEC SQL begin declare section; varchar v_a[maxrow][11]; EXEC SQL end declare section; MAIN(TPSVCINFO *msg) char *sndbuf, *rcvbuf; int i=0, errno; long len, ret; printf("[mainsvr] START\n"); printf("[mainsvr] CURSOR DECLARE\n"); EXEC SQL DECLARE cur_test_sel CURSOR FOR SELECT NVL(a,' ') FROM test_sel WHERE rownum <= 6; Tmax Programming Guide (UCS)

printf("[mainsvr] CURSOR OPEN\n"); EXEC SQL OPEN cur_test_sel; printf("[mainsvr] open cursor error : %d\n", sqlcasqlcode); if ( sqlcasqlcode!= 0 ) error processing printf("[mainsvr] CURSOR FETCH\n"); EXEC SQL FETCH cur_test_sel into :v_a; if (sqlcasqlcode < 0) errno = sqlcasqlcode; printf("[mainsvr] Fetch error : %d", errno); printf("[mainsvr] CURSOR CLOSE\n"); EXEC SQL CLOSE cur_test_sel; printf("[mainsvr] TPRETURN FAIL\n"); tpreturn( TPFAIL, errno, (char *)NULL, 0, 0 ); printf("[mainsvr] CURSOR CLOSE\n"); EXEC SQL CLOSE cur_test_sel; for(i=0; i<maxrow; i++) sndbuf = (char *)tpalloc("string", 0, 0); rcvbuf = (char *)tpalloc("string", 0, 0); v_a[i]arr[v_a[i]len] = 0; strcpy(sndbuf, v_a[i]arr); printf("[mainsvr] %d : %s / %s\n", i, v_a[i]arr, sndbuf); printf("[mainsvr] TX_BEGIN\n"); ret = tx_begin(); if (ret < 0) error processing printf("[mainsvr] INSERT\n"); if(tpcall("ins", sndbuf, strlen(sndbuf), &rcvbuf, &len, 0)<0) error processing else /* Success */ printf("[mainsvr] TX_COMMIT\n"); EXEC SQL DELETE FROM TEST_SEL WHERE A = :sndbuf; if(sqlcasqlcode!= 0) printf("[mainsvr] delete error : %d\n", sqlcasqlcode); Tmax Programming Guide (UCS)

ret = tx_rollback(); if (ret < 0) error processing error processing tpfree(sndbuf); tpfree(rcvbuf); ret = tx_commit(); if (ret < 0) error processing tpreturn( TPSUCCESS, 0, (char *)NULL, 0, 0 ); Server Program (inssvrpc ) #include <stdioh> #include <ctypeh> #include <usrinc/atmih> EXEC SQL include sqlcah; INS( TPSVCINFO *msg ) char *buf; int i=0, errno; long len; printf("woong : START\n"); buf = (char *)msg->data; printf("%s\n", buf); printf("woong : INSERT\n"); EXEC SQL INSERT INTO TEST_INS VALUES(:buf); if (sqlcasqlcode!= 0 ) error processing Tmax Programming Guide (UCS)

fflush(stdout); tpreturn(tpsuccess, 0, (char *)NULL, 0, 0 ); [mainsvr] START [mainsvr] CURSOR DECLARE [mainsvr] CURSOR OPEN [mainsvr] open cursor error : 0 [mainsvr] CURSOR FETCH [mainsvr] CURSOR CLOSE [mainsvr] 0 : aaaaa / aaaaa [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START aaaaa woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] 1 : bbbbb / bbbbb [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START bbbbb woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] 2 : ccccc / ccccc [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START ccccc woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] 3 : ddddd / ddddd [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START ddddd Tmax Programming Guide (UCS)

woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] 4 : eeeee / eeeee [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START eeeee woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] 5 : fffff / fffff [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START fffff woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT 6 select [mainsvr] TPRETURN SUCCESS [mainsvr] START [mainsvr] CURSOR DECLARE [mainsvr] CURSOR OPEN [mainsvr] open cursor error : 0 [mainsvr] CURSOR FETCH [mainsvr] CURSOR CLOSE [mainsvr] 0 : aaaaa / aaaaa [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START aaaaa woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] delete error : 1403 [mainsvr] TPRETURN FAIL [mainsvr] START [mainsvr] CURSOR DECLARE [mainsvr] CURSOR OPEN [mainsvr] open cursor error : 0 [mainsvr] CURSOR FETCH [mainsvr] CURSOR CLOSE [mainsvr] 0 : aaaaa / aaaaa [mainsvr] TX_BEGIN [mainsvr] INSERT woong : START aaaaa Tmax Programming Guide (UCS)

woong : INSERT woong : TPRETURN SUCCESS [mainsvr] TX_COMMIT [mainsvr] delete error : 1403 [mainsvr] TPRETURN FAIL tableselect, SQL> select * from test_ins; NAME -------------------- bbbbb ccccc ddddd eeeee fffff aaaaa 6 rows selected SQL> select * from test_sel; no rows selected Tmax Programming Guide (UCS)

53 RDP 531 RDP RDP REAL shared memory RDP shared memory UNREAL Config File *DOMAIN tmax1 SHMKEY=73060, MINCLH=2, MAXCLH=2, TPORTNO=8800 *NODE tmaxs1 *SVRGROUP svg1 *SERVER realsvr realtest *SERVICE REAL UNREAL TMAXDIR ="/home/tmax ", APPDIR = "/home/tmax/appbin", PATHDIR = "/home/tmax/path", TLOGDIR = "/home/tmax/log/tlog", ULOGDIR = "/home/tmax/log/ulog", SLOGDIR = "/home/tmax/log/slog", REALSVR="realtest", RSCPC = 16 NODENAME = "tmaxs1" SVGNAME = svg1 SVGNAME = svg1, MIN = 2, MAX = 2, SVRTYPE = REALSVR, MAXRSTART = 0 # UCS TCS TypeService SVRNAME = ucssvr SVRNAME = ucssvr Client Program Tmax Programming Guide (UCS)

#include <stdioh> #include <usrinc/atmih> #include <usrinc/ucsh> main(int argc, char *argv[]) char *sndbuf; char *rcvbuf; long rcvlen; int RecvCnt = 0, ret; if(tpstart((tpstart_t *)NULL) == -1) error processing tpsetunsol_flag(tpunsol_poll); if((sndbuf = (char *)tpalloc("carray", NULL, 1024)) == NULL) error processing if((rcvbuf = (char *)tpalloc("carray", NULL, 1024)) == NULL) error processing if(tpcall("real", sndbuf, 1024, &rcvbuf, &rcvlen, 0) == -1) error processing while(1) ret = tpgetunsol(unsol_tpsendtocli, &rcvbuf, &rcvlen, TPBLOCK); printf("loop Count : %d\n", RecvCnt); if(ret > 0) printf("ret message[%s]\n, rcvbuf); RecvCnt ++; if (RecvCnt == 10) break; if(tpcall("unreal", sndbuf, 1024, &rcvbuf, &rcvlen, 0) == -1) error processing RecvCnt = 0; while(1) ret = tpgetunsol(unsol_tpsendtocli, &rcvbuf, &rcvlen, TPBLOCK); printf("loop Count : %d\n", RecvCnt); if(ret > 0) printf("ret message[%s]\n, rcvbuf); Tmax Programming Guide (UCS)

RecvCnt ++; if (RecvCnt == 10) break; tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); Server Program ( realsvrc ) #include #include #include #include #include #include #include <stdioh> <sys/typesh> <sys/ipch> <sys/shmh> <sys/timeh> <usrinc/tmaxapih> <usrinc/ucsh> int shm_creator = 0; int *shm; int id; #define TABLE_SIZE (FD_SETSIZE * 10) tpsvrinit(int argc, char *argv[]) int i; id = shmget(0x12345, TABLE_SIZE * sizeof(int), IPC_CREAT IPC_EXCL SHM_R SHM_W); if (id < 0) id = shmget(0x12345, TABLE_SIZE * sizeof(int), 0); if (id < 0) error processing else shm_creator = 1; shm = (int *)shmat(id, 0, 0); if (shm == (void*)-1) error processing if (shm_creator) for (i = 0; i < TABLE_SIZE; i++) shm[i] = -1; printf("svr20 started\n"); return 1; Tmax Programming Guide (UCS)

tpsvrdone() shmdt((char *)shm); if (shm_creator) shmctl(id, IPC_RMID, (struct shmid_ds *) 0); printf("svr20 closed\n"); REAL(TPSVCINFO *rqst) int i, clid; clid = tpgetclid(); for (i = 0; i < TABLE_SIZE; i++) if (shm[i] == clid) shm[i] = -1; for (i = 0; i < TABLE_SIZE; i++) if (shm[i] == -1) shm[i] = clid; break; tpreturn(tpsuccess, 0, rqst->data, rqst->len, 0); UNREAL(TPSVCINFO *rqst) int i, clid; clid = tpgetclid(); for (i = 0; i < TABLE_SIZE; i++) if (shm[i] == clid) shm[i] = -1; usleep(10000); tpreturn(tpsuccess, 0, rqst->data, rqst->len, 0); Server Program ( realtestc ) #include <stdioh> #include <sys/typesh> #include <sys/ipch> #include <sys/shmh> #include <sys/timeh> #include <sys/timebh> #include <usrinc/tmaxapih> #include <usrinc/ucsh> Tmax Programming Guide (UCS)

int shm_creator = 0; int *shm; int id; #define TABLE_SIZE (FD_SETSIZE * 10) #define MSG_LEN (1024-20) #define SEND_INTERVAL (100000) long time_diff(struct timeval *a, struct timeval *b) long sec, usec; sec = a->tv_sec - b->tv_sec; usec = a->tv_usec - b->tv_usec; return (sec * 1000000 + usec); tpsvrinit(int argc, char *argv[]) int i; id = shmget(0x12345, TABLE_SIZE * sizeof(int), IPC_CREAT IPC_EXCL SHM_R SHM_W); if (id < 0) id = shmget(0x12345, TABLE_SIZE * sizeof(int), 0); if (id < 0) error processing else shm_creator = 1; shm = (int *)shmat(id, 0, 0); if (shm == (void*)-1) error processing if (shm_creator) for (i = 0; i < TABLE_SIZE; i++) shm[i] = -1; printf("realsvr started\n"); return 1; tpsvrdone() shmdt((char *)shm); if (shm_creator) shmctl(id, IPC_RMID, (struct shmid_ds *) 0); printf("realsvr closed\n"); Tmax Programming Guide (UCS)

usermain(int argc, char *argv[]) char *sndbuf; long sndlen; int i, n, msgid, previd, clid; int fail, delay, loop; long diff; struct timeval cur, prev, prev_stat; int max, mine; max = tpgetminsvr(); mine = tpgetsvrseqno(); if ((sndbuf = (char *)tpalloc("carray",null, 2048)) == NULL) error processing msgid = previd = fail = delay = 0; gettimeofday(&prev, NULL); prev_stat = prev; while(1) gettimeofday(&cur, NULL); if (mine == (max - 1)) diff = time_diff(&cur, &prev_stat); if (diff >= 3975000) printf("realsvr: Sent = %d, fail = %d, delay = %d, " "int = %d:%06d\n", msgid - previd, fail, delay, diff / 1000000, diff % 1000000); previd = msgid; delay = fail = 0; prev_stat = cur; diff = time_diff(&cur, &prev); if (diff < SEND_INTERVAL) tpuschedule(send_interval - diff); else delay++; if (diff >= (SEND_INTERVAL * 2)) printf("long Schedule delay %d\n", diff); gettimeofday(&prev, NULL); for (i = 0; i < TABLE_SIZE; i++) clid = shm[i]; if (tpchkclid(clid) < 0) continue; sprintf(sndbuf, "Msg(%d) sent to clid = %#x", msgid++, clid); n = tpsendtocli(clid, sndbuf, MSG_LEN, TPFLOWCONTROL); Tmax Programming Guide (UCS)