about summary refs log tree commit diff stats
path: root/092socket.mu
Commit message (Expand)AuthorAgeFilesLines
* 3987Kartik K. Agaram2017-09-011-1/+1
* 3705 - switch to tested file-system primitivesKartik K. Agaram2016-12-111-1/+1
* 3656Kartik K. Agaram2016-11-101-1/+1
* 3602Kartik K. Agaram2016-10-271-13/+7
* 3601Kartik K. Agaram2016-10-271-1/+1
* 3586Kartik K. Agaram2016-10-241-6/+6
* 3585Kartik K. Agaram2016-10-241-7/+0
* 3581Kartik K. Agaram2016-10-241-1/+16
* 3580Kartik K. Agaram2016-10-241-1/+1
* 3574Kartik K. Agaram2016-10-231-11/+11
* 3573 - client socket testsKartik K. Agaram2016-10-231-2/+23
* 3572 - new way to write server testsKartik K. Agaram2016-10-231-126/+43
* 3571 - make 'read-from-socket' non-blockingKartik K. Agaram2016-10-231-1/+8
* 3564Kartik K. Agaram2016-10-231-1/+34
* 3562Kartik K. Agaram2016-10-221-125/+105
* 3561Kartik K. Agaram2016-10-221-105/+125
* 3535Kartik K. Agaram2016-10-201-2/+2
* 3523 - http client now workingKartik K. Agaram2016-10-201-5/+47
* 3519 - reading lots of data from a socketKartik K. Agaram2016-10-181-3/+6
* 3518Kartik K. Agaram2016-10-181-2/+0
* 3511Kartik K. Agaram2016-10-161-3/+3
* 3510Kartik K. Agaram2016-10-161-0/+37
* 3507Kartik K. Agaram2016-10-161-4/+4
* 3476Kartik K. Agaram2016-10-071-1/+1
* 3465Kartik K. Agaram2016-10-071-5/+8
* 3464Kartik K. Agaram2016-10-071-2/+1
* 3463Kartik K. Agaram2016-10-071-5/+4
* 3458Stephen Malina2016-10-071-0/+116
revision' href='/akkartik/mu/blame/channel.mu?h=hlt&id=14b33e59a528b996f682110564182524d1503e91'>^
760f683f ^
b96af395 ^
77d5b5d6 ^
104854ca ^
b96af395 ^

9458918f ^
5b22547b ^
b96af395 ^
08f4628e ^
b96af395 ^

f192d655 ^
b96af395 ^
f192d655 ^
1ead3562 ^
77d5b5d6 ^
760f683f ^
b96af395 ^
192d59d3 ^

ce87c19e ^

b96af395 ^
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
40
41
42
43
44
45

                                                                
                                                   
                                          
             
                  
         
                  
   
                                  
                      
                                                  
                             
 
                         
                 
        
   
            
 
 
                                                           
                                             
             
                  

                                      
                                            
                 
                                                  
                                  

        
   
 
 
          
             
                                                                  
                                                                  

                                                

                           
 
# example program: communicating between routines using channels

def producer sink:&:sink:char -> sink:&:sink:char [
  # produce characters 1 to 5 on a channel
  local-scope
  load-ingredients
  # n = 0
  n:char <- copy 0
  {
    done?:bool <- lesser-than n, 5
    break-unless done?
    # other threads might get between these prints
    $print [produce: ], n, [ 
]
    sink <- write sink, n
    n <- add n, 1
    loop
  }
  close sink
]

def consumer source:&:source:char -> source:&:source:char [
  # consume and print integers from a channel
  local-scope
  load-ingredients
  {
    # read an integer from the channel
    n:char, eof?:bool, source <- read source
    break-if eof?
    # other threads might get between these prints
    $print [consume: ], n:char, [ 
]
    loop
  }
]

def main [
  local-scope
  source:&:source:char, sink:&:sink:char <- new-channel 3/capacity
  # create two background 'routines' that communicate by a channel
  routine1:num <- start-running producer, sink
  routine2:num <- start-running consumer, source
  wait-for-routine routine1
  wait-for-routine routine2
]