[Gambas-user] UDP socket component & UDP broadcasts

Daniel Campos dcamposf at ...626...
Mon Dec 12 12:31:15 CET 2005


Ok, finally I found time to add the patch. I did not found any reason to
limit the use of  any of the two options, so I've added the patch directly
to the CUdpSocket.c file. Benoît, could you replace the existing one in the
gb.net component? In the future I will try to add more options but I'm quite
busy now... May be p.r. Faassewould like to do it? :-)

Regards,

D. Campos

2005/12/6, p.r. faasse <faasse at ...1252...>:
>
> On Friday 02 December 2005 22:37, Daniel Campos wrote:
> > Hi:
> >
> > Could you send me your patch? I will add it!
> >
> > thanks,
> >
> > D. Campos
>
> Hold on to your hat: here it comes: I've limited the code to the
> dgram_start routine of CUdpSocket.c, to not
> bother you with all sections of code that i have *not* modified. My
> modifications are between the <prf> and </prf> comment
> lines. Note that i have misused the error-code: error code 10 is probably
> not the best one possible, but i have not found anything
> better in the list of socket error codes.
>
> int dgram_start(CUDPSOCKET *mythis,int myport)
> {
>         int NoBlock=1;
>         // <prf>
>         const int on = 1;
>         // </prf>
>         struct sockaddr_in Srv;
>
>         if (mythis->iStatus > 0) return 1;
>         if ( (myport <0) || (myport>65535) ) return 8;
>
>         if ( (mythis->Socket = socket(AF_INET,SOCK_DGRAM,0))<1 )
>         {
>                 mythis->iStatus=-2;
>                 GB.Ref(mythis);
>                 GB.Post(CUdpSocket_post_error,(long)mythis);
>                 return 2;
>         }
>
>         //
>         // <prf>
>         //
>         // enable broadcasts, reuseaddress
>         //
>         if ( setsockopt(mythis->Socket, SOL_SOCKET, SO_REUSEADDR, &on,
> sizeof(on)) ) {
>                 //
>                 close (mythis->Socket);
>                 mythis->iStatus=-10;
>                 GB.Ref(mythis);
>                 GB.Post(CUdpSocket_post_error,(long)mythis);
>                 return 10;
>                 //
>         }
>         //
>         if ( setsockopt(mythis->Socket, SOL_SOCKET, SO_BROADCAST, &on,
> sizeof(on)) ) {
>                 //
>                 close (mythis->Socket);
>                 mythis->iStatus=-10;
>                 GB.Ref(mythis);
>                 GB.Post(CUdpSocket_post_error,(long)mythis);
>                 return 10;
>                 //
>         }
>         //
>         // </prf>
>         //
>
>
>         Srv.sin_family=AF_INET;
>         Srv.sin_addr.s_addr=htonl(INADDR_ANY);
>         Srv.sin_port=htons(myport);
>         bzero(&(Srv.sin_zero),8);
>
>         if ( bind (mythis->Socket,(struct sockaddr*)&Srv,sizeof(struct
> sockaddr)) < 0)
>         {
>                 close (mythis->Socket);
>                 mythis->iStatus=-10;
>                 GB.Ref(mythis);
>                 GB.Post(CUdpSocket_post_error,(long)mythis);
>                 return 10;
>         }
>
>         mythis->iStatus=1;
>         ioctl(mythis->Socket,FIONBIO,&NoBlock);
>         GB.Watch (mythis->Socket,GB_WATCH_WRITE,(void
> *)CUdpSocket_CallBack,(long)mythis);
>         mythis->stream.desc=&UdpSocketStream;
>         mythis->stream._free[0]=(long)mythis;
>         return 0;
> }
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20051212/0cb730eb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CUdpSocket.c
Type: text/x-csrc
Size: 12293 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20051212/0cb730eb/attachment.c>


More information about the User mailing list