[PD-cvs] externals/mrpeach/net tcpsend.c,1.1,1.2

Martin Peach mrpeach at users.sourceforge.net
Tue Nov 7 22:19:31 CET 2006


Update of /cvsroot/pure-data/externals/mrpeach/net
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13997

Modified Files:
	tcpsend.c 
Log Message:
added file send


Index: tcpsend.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/net/tcpsend.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tcpsend.c	24 Aug 2006 06:51:16 -0000	1.1
--- tcpsend.c	7 Nov 2006 21:19:29 -0000	1.2
***************
*** 8,11 ****
--- 8,13 ----
  #include "m_pd.h"
  #include "s_stuff.h"
+ #include <stdio.h>
+ #include <string.h>
  
  #ifdef MSW
***************
*** 17,22 ****
  #include <netinet/tcp.h>
  #include <netdb.h>
- #include <stdio.h>
- #include <string.h>
  #endif
  
--- 19,22 ----
***************
*** 29,35 ****
  } t_tcpsend;
  
- #ifdef MSW
- __declspec(dllexport)
- #endif
  void tcpsend_setup(void);
  static void tcpsend_free(t_tcpsend *x);
--- 29,32 ----
***************
*** 116,121 ****
  static void tcpsend_send(t_tcpsend *x, t_symbol *s, int argc, t_atom *argv)
  {
!     static char    byte_buf[65536];// arbitrary maximum similar to max IP packet size
!     int            i, d;
      char           c;
      float          f, e;
--- 113,119 ----
  static void tcpsend_send(t_tcpsend *x, t_symbol *s, int argc, t_atom *argv)
  {
! #define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size
!     static char    byte_buf[BYTE_BUF_LEN];
!     int            i, j, d;
      char           c;
      float          f, e;
***************
*** 128,131 ****
--- 126,131 ----
      double         timeafter;
      int            late;
+     char           fpath[MAX_PATH];
+     FILE           *fptr;
  
  #ifdef DEBUG
***************
*** 133,137 ****
      post("argc: %d", argc);
  #endif
!     for (i = 0; i < argc; ++i)
      {
          if (argv[i].a_type == A_FLOAT)
--- 133,137 ----
      post("argc: %d", argc);
  #endif
!     for (i = j = 0; i < argc; ++i)
      {
          if (argv[i].a_type == A_FLOAT)
***************
*** 154,167 ****
  	        post("tcpsend_send: argv[%d]: %d", i, c);
  #endif
! 	        byte_buf[i] = c;
          }
          else
  	    {
!             error("tcpsend_send: item %d is not a float", i);
              return;
          }
      }
  
!     length = i;
      if ((x->x_fd >= 0) && (length > 0))
      {
--- 154,200 ----
  	        post("tcpsend_send: argv[%d]: %d", i, c);
  #endif
! 	        byte_buf[j++] = c;
!         }
!         else if (argv[i].a_type == A_SYMBOL)
!         {
! 
!             atom_string(&argv[i], fpath, MAX_PATH);
! #ifdef DEBUG
!             post ("tcpsend fname: %s", fpath);
! #endif
!             fptr = fopen(fpath, "rb");
!             if (fptr == NULL)
!             {
!                 post("tcpsend: unable to open \"%s\"", fpath);
!                 return;
!             }
!             rewind(fptr);
! #ifdef DEBUG
!             post("tcpsend: d is %d", d);
! #endif
!             while ((d = fgetc(fptr)) != EOF)
!             {
!                 byte_buf[j++] = (char)(d & 0x0FF);
! #ifdef DEBUG
!                 post("tcpsend: byte_buf[%d] = %d", j-1, byte_buf[j-1]);
! #endif
!                 if (j >= BYTE_BUF_LEN)
!                 {
!                     post ("tcpsend: file too long, truncating at %lu", BYTE_BUF_LEN);
!                     break;
!                 }
!             }
!             fclose(fptr);
!             fptr = NULL;
!             post("tcpsend: read \"%s\" length %d byte%s", fpath, j, ((d==1)?"":"s"));
          }
          else
  	    {
!             error("tcpsend_send: item %d is not a float or a file name", i);
              return;
          }
      }
  
!     length = j;
      if ((x->x_fd >= 0) && (length > 0))
      {
***************
*** 204,210 ****
  }
  
- #ifdef MSW
- __declspec(dllexport)
- #endif
  void tcpsend_setup(void)
  {
--- 237,240 ----





More information about the Pd-cvs mailing list