comm.c (110560) | comm.c (111823) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers. | 2 * Copyright (c) 1999-2003 Sendmail, Inc. and its suppliers. |
3 * All rights reserved. 4 * 5 * By using this file, you agree to the terms and conditions set 6 * forth in the LICENSE file which can be found at the top level of 7 * the sendmail distribution. 8 * 9 */ 10 11#include <sm/gen.h> | 3 * All rights reserved. 4 * 5 * By using this file, you agree to the terms and conditions set 6 * forth in the LICENSE file which can be found at the top level of 7 * the sendmail distribution. 8 * 9 */ 10 11#include <sm/gen.h> |
12SM_RCSID("@(#)$Id: comm.c,v 8.54.2.4 2002/12/03 17:32:45 ca Exp $") | 12SM_RCSID("@(#)$Id: comm.c,v 8.54.2.6 2003/01/03 22:14:40 ca Exp $") |
13 14#include "libmilter.h" 15#include <sm/errstring.h> 16 | 13 14#include "libmilter.h" 15#include <sm/errstring.h> 16 |
17#define FD_Z FD_ZERO(&readset); \ 18 FD_SET((unsigned int) sd, &readset); \ 19 FD_ZERO(&excset); \ 20 FD_SET((unsigned int) sd, &excset) 21 | |
22/* 23** MI_RD_CMD -- read a command 24** 25** Parameters: 26** sd -- socket descriptor 27** timeout -- maximum time to wait 28** cmd -- single character command read from sd 29** rlen -- pointer to length of result --- 11 unchanged lines hidden (view full) --- 41 struct timeval *timeout; 42 char *cmd; 43 size_t *rlen; 44 char *name; 45{ 46 ssize_t len; 47 mi_int32 expl; 48 ssize_t i; | 17/* 18** MI_RD_CMD -- read a command 19** 20** Parameters: 21** sd -- socket descriptor 22** timeout -- maximum time to wait 23** cmd -- single character command read from sd 24** rlen -- pointer to length of result --- 11 unchanged lines hidden (view full) --- 36 struct timeval *timeout; 37 char *cmd; 38 size_t *rlen; 39 char *name; 40{ 41 ssize_t len; 42 mi_int32 expl; 43 ssize_t i; |
49 fd_set readset, excset; | 44 FD_RD_VAR(rds, excs); |
50 int ret; 51 int save_errno; 52 char *buf; 53 char data[MILTER_LEN_BYTES + 1]; 54 55 *cmd = '\0'; 56 *rlen = 0; 57 58 i = 0; 59 for (;;) 60 { | 45 int ret; 46 int save_errno; 47 char *buf; 48 char data[MILTER_LEN_BYTES + 1]; 49 50 *cmd = '\0'; 51 *rlen = 0; 52 53 i = 0; 54 for (;;) 55 { |
61 FD_Z; 62 ret = select(sd + 1, &readset, NULL, &excset, timeout); | 56 FD_RD_INIT(sd, rds, excs); 57 ret = FD_RD_READY(sd, rds, excs, timeout); |
63 if (ret == 0) 64 break; 65 else if (ret < 0) 66 { 67 if (errno == EINTR) 68 continue; 69 break; 70 } | 58 if (ret == 0) 59 break; 60 else if (ret < 0) 61 { 62 if (errno == EINTR) 63 continue; 64 break; 65 } |
71 if (FD_ISSET(sd, &excset)) | 66 if (FD_IS_RD_EXC(sd, rds, excs)) |
72 { 73 *cmd = SMFIC_SELECT; 74 return NULL; 75 } 76 77 len = MI_SOCK_READ(sd, data + i, sizeof data - i); 78 if (MI_SOCK_READ_FAIL(len)) 79 { --- 46 unchanged lines hidden (view full) --- 126 { 127 *cmd = SMFIC_MALLOC; 128 return NULL; 129 } 130 131 i = 0; 132 for (;;) 133 { | 67 { 68 *cmd = SMFIC_SELECT; 69 return NULL; 70 } 71 72 len = MI_SOCK_READ(sd, data + i, sizeof data - i); 73 if (MI_SOCK_READ_FAIL(len)) 74 { --- 46 unchanged lines hidden (view full) --- 121 { 122 *cmd = SMFIC_MALLOC; 123 return NULL; 124 } 125 126 i = 0; 127 for (;;) 128 { |
134 FD_Z; 135 ret = select(sd + 1, &readset, NULL, &excset, timeout); | 129 FD_RD_INIT(sd, rds, excs); 130 ret = FD_RD_READY(sd, rds, excs, timeout); |
136 if (ret == 0) 137 break; 138 else if (ret < 0) 139 { 140 if (errno == EINTR) 141 continue; 142 break; 143 } | 131 if (ret == 0) 132 break; 133 else if (ret < 0) 134 { 135 if (errno == EINTR) 136 continue; 137 break; 138 } |
144 if (FD_ISSET(sd, &excset)) | 139 if (FD_IS_RD_EXC(sd, rds, excs)) |
145 { 146 *cmd = SMFIC_SELECT; 147 free(buf); 148 return NULL; 149 } 150 len = MI_SOCK_READ(sd, buf + i, expl - i); 151 if (MI_SOCK_READ_FAIL(len)) 152 { --- 65 unchanged lines hidden (view full) --- 218** we don't care much about the timeout here, it's very long anyway 219** FD_SETSIZE is checked when socket is created. 220** XXX l == 0 ? 221*/ 222 223#define MI_WR(data) \ 224 while (sl > 0) \ 225 { \ | 140 { 141 *cmd = SMFIC_SELECT; 142 free(buf); 143 return NULL; 144 } 145 len = MI_SOCK_READ(sd, buf + i, expl - i); 146 if (MI_SOCK_READ_FAIL(len)) 147 { --- 65 unchanged lines hidden (view full) --- 213** we don't care much about the timeout here, it's very long anyway 214** FD_SETSIZE is checked when socket is created. 215** XXX l == 0 ? 216*/ 217 218#define MI_WR(data) \ 219 while (sl > 0) \ 220 { \ |
226 FD_ZERO(&wrtset); \ 227 FD_SET((unsigned int) sd, &wrtset); \ 228 ret = select(sd + 1, NULL, &wrtset, NULL, timeout); \ | 221 FD_WR_INIT(sd, wrs); \ 222 ret = FD_WR_READY(sd, wrs, timeout); \ |
229 if (ret == 0) \ 230 return MI_FAILURE; \ 231 if (ret < 0) \ 232 { \ 233 if (errno == EINTR) \ 234 continue; \ 235 else \ 236 return MI_FAILURE; \ --- 17 unchanged lines hidden (view full) --- 254 int cmd; 255 char *buf; 256 size_t len; 257{ 258 size_t sl, i; 259 ssize_t l; 260 mi_int32 nl; 261 int ret; | 223 if (ret == 0) \ 224 return MI_FAILURE; \ 225 if (ret < 0) \ 226 { \ 227 if (errno == EINTR) \ 228 continue; \ 229 else \ 230 return MI_FAILURE; \ --- 17 unchanged lines hidden (view full) --- 248 int cmd; 249 char *buf; 250 size_t len; 251{ 252 size_t sl, i; 253 ssize_t l; 254 mi_int32 nl; 255 int ret; |
262 fd_set wrtset; | 256 FD_WR_VAR(wrs); |
263 char data[MILTER_LEN_BYTES + 1]; 264 265 if (len > MILTER_CHUNK_SIZE) 266 return MI_FAILURE; 267 nl = htonl(len + 1); /* add 1 for the cmd char */ 268 (void) memcpy(data, (void *) &nl, MILTER_LEN_BYTES); 269 data[MILTER_LEN_BYTES] = (char) cmd; 270 i = 0; --- 14 unchanged lines hidden --- | 257 char data[MILTER_LEN_BYTES + 1]; 258 259 if (len > MILTER_CHUNK_SIZE) 260 return MI_FAILURE; 261 nl = htonl(len + 1); /* add 1 for the cmd char */ 262 (void) memcpy(data, (void *) &nl, MILTER_LEN_BYTES); 263 data[MILTER_LEN_BYTES] = (char) cmd; 264 i = 0; --- 14 unchanged lines hidden --- |