Subversion Repositories MLServ

Rev

Rev 7 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 9
Line 1... Line 1...
1
/* $Id: server.c 7 2024-09-25 00:56:55Z nishi $ */
1
/* $Id: server.c 9 2024-09-25 01:17:09Z nishi $ */
2
 
2
 
3
#include "ms_server.h"
3
#include "ms_server.h"
4
 
4
 
5
#include <stdio.h>
5
#include <stdio.h>
6
#include <poll.h>
6
#include <poll.h>
Line 35... Line 35...
35
		int ret = poll(pollfds, 1, 5000);
35
		int ret = poll(pollfds, 1, 5000);
36
		if(ret < 0) {
36
		if(ret < 0) {
37
			break;
37
			break;
38
		} else if(ret == 0) {
38
		} else if(ret == 0) {
39
			strsend(sock, "TIMEOUT\n");
39
			strsend(sock, "TIMEOUT\n");
40
			break;
40
			goto nobye;
41
		} else {
41
		} else {
42
			int i;
42
			int i;
43
			char buffer[512];
43
			char buffer[512];
44
			char cbuf[2];
44
			char cbuf[2];
45
			cbuf[1] = 0;
45
			cbuf[1] = 0;
46
			int len = recv(sock, buffer, 512, 0);
46
			int len = recv(sock, buffer, 512, 0);
-
 
47
			if(len <= 0) break;
47
			for(i = 0; i < len; i++) {
48
			for(i = 0; i < len; i++) {
48
				if(buffer[i] == '\n') {
49
				if(buffer[i] == '\n') {
49
					if(strcmp(line, "BYE") == 0) {
50
					if(strcmp(line, "BYE") == 0) {
50
						goto brk;
51
						goto brk;
51
					} else if(strcmp(line, "LIST-ML") == 0) {
52
					} else if(strcmp(line, "LIST-ML") == 0) {
52
						char** list = cm_list_ml(db);
53
						char** list = cm_list_ml(db);
53
						if(list != NULL) {
54
						if(list != NULL) {
-
 
55
							int j;
54
							strsend(sock, "BEGIN\n");
56
							strsend(sock, "BEGIN\n");
-
 
57
							for(j = 0; list[j] != NULL; j += 2) {
-
 
58
								strsend(sock, list[j + 0]);
-
 
59
								strsend(sock, "\t");
-
 
60
								strsend(sock, list[j + 1]);
-
 
61
								strsend(sock, "\n");
-
 
62
								free(list[j + 0]);
-
 
63
								free(list[j + 1]);
-
 
64
							}
55
							strsend(sock, "END\n");
65
							strsend(sock, "END\n");
56
							int j;
-
 
57
							for(j = 0; list[j] != NULL; j++) free(list[j]);
-
 
58
							free(list);
66
							free(list);
59
						} else {
67
						} else {
60
							strsend(sock, "DBERROR\n");
68
							strsend(sock, "DBERROR\n");
61
							goto nobye;
69
							goto nobye;
62
						}
70
						}