Beispiel #1
0
// rc < 0 on comm failures
// rc == 1 indicates comm success
extern  int
proto_session_send_msg(Proto_Session *s, int reset)
{
    s->shdr.blen = htonl(s->slen);
    
    // write request
    if (net_writen(s->fd, &(s->shdr), sizeof(s->shdr)) != sizeof(s->shdr))
        return -1;
    
    if (s->slen) {
        if (net_writen(s->fd, s->sbuf, s->slen) != s->slen) {
            return -2;
        }
    }
    
    if (proto_debug()) {
        fprintf(stderr, "%p: proto_session_send_msg: SENT:\n", pthread_self());
        proto_session_dump(s);
    }
    
    // communication was successfull
    if (reset) proto_session_reset_send(s);
    
    return 1;
}
Beispiel #2
0
void
str_echo(int sockfd)
{
  int n;
  int  len;
  char *buf;
  
  while (1) {
    //COMPLETED THE MISSING AND IMPORTANT LINE HERE
      n = net_readn(sockfd, &len, sizeof(int));
    if (n != sizeof(int)) {
      fprintf(stderr, "%s: ERROR failed to read len: %d!=%d"
	      " ... closing connection\n", __func__, n, (int)sizeof(int));
      break;
    } 
    //WHAT DOES THE NEXT LINE DO?
    len = ntohl(len);
    if (len) {
      buf = (char *)malloc(len);
      n = net_readn(sockfd, buf, len);
      if ( n != len ) {
	fprintf(stderr, "%s: ERROR failed to read msg: %d!=%d"
		" .. closing connection\n" , __func__, n, len);
	break;
      }
      VPRINTF("got: %d '%s'\n", len, buf);
      net_writen(sockfd, buf, len);
      free(buf);
    }
  }
  close(sockfd);
  return;
}
Beispiel #3
0
// rc < 0 on comm failures
// rc == 1 indicates comm success
// session passed to us contains header and body information,
// need to send that information to fd
extern  int
proto_session_send_msg(Proto_Session *s, int reset){
  s->shdr.blen = htonl(s->slen);

  if(net_writen(s->fd, &(s->shdr), sizeof(Proto_Msg_Hdr)) < 0)
    return -1;
  net_writen(s->fd, s->sbuf, s->slen);

  if (proto_debug()) {
    fprintf(stderr, "%p: proto_session_send_msg: SENT:\n", pthread_self());
    proto_session_dump(s);
  }

  if (reset) proto_session_reset_send(s);

  return 1;
}
Beispiel #4
0
// rc < 0 on comm failures
// rc == 1 indicates comm success
extern  int
proto_session_send_msg(Proto_Session *s, int reset)
{
  s->shdr.blen = htonl(s->slen);

  // write request
  // ADD CODE
  net_writen(s->fd, &s->shdr, (int)sizeof(Proto_Msg_Hdr));

  if (s->slen>0) {
    net_writen(s->fd, &s->sbuf, (int)s->slen);
     if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "Sending extra bytes: %d\n", s->slen);
  }
  
  if (proto_debug()) {
    fprintf(stderr, "%p: proto_session_send_msg: SENT:\n", pthread_self());
    proto_session_dump(s);
  }

  if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "Sent message...\n");

// ////////////

//   struct sockaddr_in sinadd;
//   socklen_t len = sizeof(sinadd);
//   if (getsockname(s->fd, (struct sockaddr *)&sinadd, &len) == -1)
//       perror("getsockname");
//   else
//       printf("port number %d\n", ntohs(sinadd.sin_port));

//     char hostname[128];

// gethostname(hostname, sizeof hostname);
// printf("My hostname: %s\n", hostname);
// ////////////

  // communication was successfull 
  if (reset) proto_session_reset_send(s);

  return 1;
}
extern int
proto_session_send_msg(Proto_Session *s, int reset) {
    //int n;
    s->shdr.blen = sizeof (s->sbuf);
    s->slen = sizeof (s->shdr);

    net_writen(s->fd, &(s->shdr), s->slen);
    net_writen(s->fd, &(s->sbuf), s->shdr.blen);


    // write request
    // ADD CODE

    if (proto_debug()) {
        fprintf(stderr, "%p: proto_session_send_msg: SENT:\n", pthread_self());
        proto_session_dump(s);
    }

    // communication was successfull 
    if (reset) proto_session_reset_send(s);

    return 1;
}