📄 dce_service.c
字号:
/***************************************Ho Chi Minh City University of Technology Computer Science Department Distributed Computing Environment (DCE)Written by Nguyen Van Noi -59406114File dce_service.c on Thu Dec 24 12:14:39 1998****************************************/#include "dce_service.h"ServiceDes Service;void dce_service_exit ();void dce_service_alive (void *);int dce_service_mcastsend (char *buf, int len);intdce_service_init (int argc, char **argv){ int n; if (argc < 9) return 0; atexit (dce_service_exit); TIMEOUT_IAMALIVE= atoi (argv[9]); Service.argc = argc; Service.argv = argv; Service.maddr = gethostaddr (argv[1]); Service.mport = atoi (argv[2]); Service.eaddr = Service.Msg.aaddr = gethostaddr (argv[3]); /*client address */ Service.eport = atoi (argv[4]); /*Client port */ Service.Msg.uid = atoi (argv[5]); /*userid */ Service.nParam = atoi (argv[6]); Service.Msg.who = SERVICE; Service.Msg.saddr = getmyaddr (); Service.Msg.order = atoi (argv[7]); /*order */ Service.Msg.nextra = atoi (argv[8]); /*service code */ Service.Msg.lextra = time (NULL); Service.Msg.pid = getpid (); if (!dce_timer_init ()) return 0; if ((Service.nMSockSend = dce_mcastsocksend ()) < 0) return 0; if ((n = dce_connect (Service.eaddr, Service.eport)) < 0) return 0; Service.Msg.type = DCE_MSG_ALL_REPLY_CLIENT_PLEASEWAIT; write (n, (void *) &Service.Msg, sizeof (MSG)); close (n); dce_service_alive (NULL); return 1;}voiddce_service_exit (){ Service.Msg.lextra1 = time (NULL); Service.Msg.type = DCE_MSG_SERVICE_REPLY_ALL_FINISH; dce_service_mcastsend ((char *) &Service.Msg, sizeof (MSG)); close (Service.nMSockSend); dce_timer_free (); _cleanup (); _exit ();}voiddce_service_alive (void *p){ static int i; int n; static MSG m; Service.nTimerId = dce_settimer (TIMEOUT_IAMALIVE, dce_service_alive, NULL); if (!i) { memcpy (&m, &Service.Msg, sizeof (MSG)); m.type = DCE_MSG_ALL_REPLY_CLIENT_PLEASEWAIT; i++; } if ((n = dce_connect (Service.eaddr, Service.eport)) < 0) exit (-1); write (n, &m, sizeof (m)); close (n); dce_service_mcastsend ((char *) &m, sizeof (m));}intdce_service_mcastsend (char *buf, int len){ return dce_mcastsendsend (Service.nMSockSend, Service.maddr, Service.mport, buf, len);}voiddce_service_senderr (){ int n; if ((n = dce_connect (Service.eaddr, Service.eport)) < 0) exit (-1); Service.Msg.type = DCE_MSG_ALL_REPLY_CLIENT_ERROR; write (n, &Service.Msg, sizeof (MSG)); close (n); exit (-1);}pmatrixdce_get_matrix (int i){ pmatrix pm; int n; if (i > Service.nParam) return NULL; if ((n = dce_connect (Service.eaddr, Service.eport)) < 0) exit (-1); Service.Msg.type = DCE_MSG_SERVICE_REQUEST_CLIENT_DATA; Service.Msg.sport = i; write (n, &Service.Msg, sizeof (MSG)); sleep (1); pm = readmatrix (n); close (n); return pm;}intdce_service_sendmatrix (pmatrix pm){ int n; if ((n = dce_connect (Service.eaddr, Service.eport)) < 0) exit (-1); Service.Msg.type = DCE_MSG_SERVICE_REPLY_CLIENT_DATA; write (n, &Service.Msg, sizeof (MSG)); writematrix (n, pm); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -