|
@@ -50,6 +50,8 @@ int do_bh(struct vcc_request *);
|
|
|
|
|
|
|
|
int fd;
|
|
int fd;
|
|
|
char usrname[USRNAME_SIZE];
|
|
char usrname[USRNAME_SIZE];
|
|
|
|
|
+static char *reading;
|
|
|
|
|
+static int size_read;
|
|
|
|
|
|
|
|
static int usage(void) {
|
|
static int usage(void) {
|
|
|
fprintf(stderr, "Usage: vcc [server]\n");
|
|
fprintf(stderr, "Usage: vcc [server]\n");
|
|
@@ -117,9 +119,9 @@ static int login(void) {
|
|
|
|
|
|
|
|
int main(int argc, const char **argv) {
|
|
int main(int argc, const char **argv) {
|
|
|
struct pollfd fds[2];
|
|
struct pollfd fds[2];
|
|
|
- struct vcc_request req;
|
|
|
|
|
|
|
+ struct vcc_request *req;
|
|
|
char *buf;
|
|
char *buf;
|
|
|
- int n;
|
|
|
|
|
|
|
+ int n, size;
|
|
|
|
|
|
|
|
if (unlikely(argc != 1 && argc != 2))
|
|
if (unlikely(argc != 1 && argc != 2))
|
|
|
return usage();
|
|
return usage();
|
|
@@ -146,8 +148,16 @@ int main(int argc, const char **argv) {
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (unlikely(!(reading = malloc(REQ_SIZE)))) {
|
|
|
|
|
+ fprintf(stderr, "*** malloc() failed\n");
|
|
|
|
|
+
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ size_read = 0;
|
|
|
|
|
+
|
|
|
for (;;) {
|
|
for (;;) {
|
|
|
- n = poll(fds, 2, 1);
|
|
|
|
|
|
|
+ n = poll(fds, 2, 1000);
|
|
|
|
|
|
|
|
if (n == -1) {
|
|
if (n == -1) {
|
|
|
if (likely(errno == EINTR))
|
|
if (likely(errno == EINTR))
|
|
@@ -190,24 +200,27 @@ int main(int argc, const char **argv) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (fds[1].revents & POLLIN) {
|
|
if (fds[1].revents & POLLIN) {
|
|
|
- if (read_msg(&req) == -1) {
|
|
|
|
|
- printf("Server closed. \n");
|
|
|
|
|
|
|
+ size = read(fd, reading + size_read, REQ_SIZE);
|
|
|
|
|
+ size_read += size;
|
|
|
|
|
|
|
|
- return 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (size_read < REQ_SIZE)
|
|
|
|
|
+ continue;
|
|
|
|
|
+
|
|
|
|
|
+ size_read = 0;
|
|
|
|
|
+ req = (struct vcc_request *) reading;
|
|
|
|
|
|
|
|
- if (ntohl(req.reqtype) != REQ_MSG_NEW) {
|
|
|
|
|
- do_bh(&req);
|
|
|
|
|
|
|
+ if (ntohl(req->reqtype) != REQ_MSG_NEW) {
|
|
|
|
|
+ do_bh(req);
|
|
|
|
|
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- buf = req.msg;
|
|
|
|
|
|
|
+ buf = req->msg;
|
|
|
|
|
|
|
|
if (!*buf || *(unsigned char *) buf == 0xffu)
|
|
if (!*buf || *(unsigned char *) buf == 0xffu)
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
- pretty_new_msg(req.usrname, buf);
|
|
|
|
|
|
|
+ pretty_new_msg(req->usrname, buf);
|
|
|
pretty_prompt(usrname);
|
|
pretty_prompt(usrname);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|