[Click] receiving data into a buffer

Beyers Cronje bcronje at gmail.com
Wed Jan 30 08:04:10 EST 2008


>
>
> Socket(TCP, 127.0.0.1,1322)->[0]my_element


Looks alright.

and in my_element.cc file if I have
>
>
> void myelement::push(int port, Packet *p)
> {
> .....
>   if (port == 0) {
>     // First input port
>     method0(p);
>   } else if (port == 1) {
>     // Second input port
>     method1(p);
>   }
> ....
> }
>
> void myelement::method0(Packet *p)
> {
> //here if I say
>     char *x=(char *)p->data()
>
> }
> then x will be the pointer to 128 bits which is received?
>

p->data() returns a const pointer, so you would have to use:
     const char *x = (const char *)p->data();

Alternatively if you need write access use the following:
     WritablePacket *wp = p->uniqueify();
     char *x = wp->data();

Also if I want to send 128 bit through click to a program outside click
> can I write my own socket element just to send ?
>

You could, but much simpler is to just use the Socket Element to send data.
You can even use the existing Socket element in your element above i.e.

sock::Socket(TCP, 127.0.0.1,1322)->[0]my_element;
my_element -> Queue -> sock;

The input port of socket is agnostic, so you could push directly into
Socket, but if pushed, packets will block on the underlying socket. If pull
input is used the socket will pull packets as it can accept them.


More information about the click mailing list