annotate contrib/unicode2nginx/unicode-to-nginx.pl @ 6949:ff0c8e11edbc

Simplified and improved sendfile() code on Linux. The ngx_linux_sendfile() function is now used for both normal sendfile() and sendfile in threads. The ngx_linux_sendfile_thread() function was modified to use the same interface as ngx_linux_sendfile(), and is simply called from ngx_linux_sendfile() when threads are enabled. Special return code NGX_DONE is used to indicate that a thread task was posted and no further actions are needed. If number of bytes sent is less that what we were sending, we now always retry sending. This is needed for sendfile() in threads as the number of bytes we are sending might have been changed since the thread task was posted. And this is also needed for Linux 4.3+, as sendfile() might be interrupted at any time and provides no indication if it was interrupted or not (ticket #1174).
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 28 Mar 2017 18:15:39 +0300
parents 8752257e883f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1 #!/usr/bin/perl -w
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 # Convert unicode mappings to nginx configuration file format.
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 # You may find useful mappings in various places, including
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6 # unicode.org official site:
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 # http://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 # Needs perl 5.6 or later.
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
6665
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
13 # Written by Maxim Dounin, mdounin@mdounin.ru
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 ###############################################################################
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 require 5.006;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 while (<>) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 # Skip comments and empty lines
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 next if /^#/;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 next if /^\s*$/;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 chomp;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 # Convert mappings
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 if (/^\s*0x(..)\s*0x(....)\s*(#.*)/) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 # Mapping <from-code> <unicode-code> "#" <unicode-name>
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 my $cs_code = $1;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 my $un_code = $2;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 my $un_name = $3;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 # Produce UTF-8 sequence from character code;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
6665
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
36 my $un_utf8 = join('',
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
37 map { sprintf("%02X", $_) }
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
38 unpack("U0C*", pack("U", hex($un_code)))
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
39 );
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 print " $cs_code $un_utf8 ; $un_name\n";
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 } else {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 warn "Unrecognized line: '$_'";
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 ###############################################################################