forked from rramsden/TCP-IP-Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadPacketSample.pl
More file actions
executable file
·39 lines (27 loc) · 862 Bytes
/
threadPacketSample.pl
File metadata and controls
executable file
·39 lines (27 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
use threads;
use Class::Struct;
#structure for packets
struct( Packet => {
data => '$',
inPacket => '$',
});
#make a new packet
$newPacket=Packet->new(data=>"11110000", inPacket=>"f");
#array to be called @Packets and add the new packet to it
push(@Packets,$newPacket);
#threads only take an array of arguments so set up the array of arguments
@args=($Packets[0]);
#create the thread first param is a string for the thread of handlePacket, and the second param is for the array of arguments
$thread = threads->create('handlePacket',@args);
#the function to handle a packet (sample code)
sub handlePacket{
#get the params
@params=@_;
#treat the first element of the array as a packet and print out the fields in it (that you have access to)
$tmp=$params[0];
print $tmp->data;
print "\n";
print $tmp->inPacket;
print "\n";
}